loop executing for 1 less than the no. of times it should execute

look at the for loop that i have written in the following code. why is it running q-1 times? it should run q times. should’nt it? here’s my code. thanks…

class MagicBoard
{

public static void main(String[] args) 
{
	
	java.util.Scanner sc = new java.util.Scanner(System.in);
	
	int n = sc.nextInt();
	if((n < 1) || (n > 500000))
		System.exit(0);
	int q = sc.nextInt();
	if((q < 1) || (q > 500000))
		System.exit(0);
	
	
	int row[] = new int[n];
	int col[] = new int[n];
	
	for(int n1 = 0; n1 < n; n1++)
	{
		row[n1] = n;
		col[n1] = n;
	}
	
	StringBuffer output = new StringBuffer("");
	int i = 0, x = 0;
	
	
	for(int q1 = 0; q1 < q; q1++)
	{
		String s = sc.nextLine();
		String s1[] = s.split(" ");
		if(s1.length == 2)
		{
			i = Integer.parseInt(s1[1]);
			if((i < 1) || (i > n))
				System.exit(0);
		}
		if(s1.length == 3)
		{
			i = Integer.parseInt(s1[1]);
			if((i < 1) || (i > n))
				System.exit(0);
			x = Integer.parseInt(s1[2]);
			if((x != 0) && (x != 1))
				System.exit(0);
		}
		if(s1[0].equals("RowQuery"))
			output.append(row[i - 1] + "\n");
		if(s1[0].equals("ColQuery"))
			output.append(col[i - 1] + "\n");
		if(s1[0].equals("RowSet"))
		{
			if(x == 0)
			{
				row[i - 1] = n;
				for(int k = 0; k < n; k++)
					col[k]++;
			}
			if(x == 1)
			{
				row[i - 1] = 0;
				for(int k = 0; k < n; k++)
					col[k]--;
			}
		}
		if(s1[0].equals("ColSet"))
		{
			if(x == 0)
			{
				col[i - 1] = n;
				for(int k = 0; k < n; k++)
					row[k]++;
			}
			if(x == 1)
			{
				col[i - 1] = 0;
				for(int k = 0; k < n; k++)
					row[k]--;
			}
		}
		
	}
	System.out.println(output);
	
}

}