How to change quality on input?

I’m trying to make a script so that when I press a key, which I want it to be Q, it will change the quality to fast, and when I press it again it will change back to good. Can this be done? Oh, and if anyone provides a script can you try to put it in C#?

Where index is the equivalent quality setting

int index;
    
if(Input.GetKeyDown(KeyCode.Space))
{
 QualitySettings.SetQualityLevel(index,true);
}
if(Input.GetKeyDown(KeyCode.Up)
{
 QualitySettings.IncreaseLevel(false);
}
if(Input.GetKeyDown(KeyCode.Down)
{
 QualitySettings.DecreaseLevel(false);
}

Not sure if that is the correct syntax but that should be close to what you want