Problem: Mike and some bears are playing a game just for fun. Mike is the judge. All bears except Mike are standing in an n × m grid, there's exactly one bear in each cell. We denote the bear standing in column number j of row number i by (i, j). Mike's hands are on his ears (since he's the judge) and each bear standing in the grid has hands either on his mouth or his eyes.

<image>

They play for q rounds. In each round, Mike chooses a bear (i, j) and tells him to change his state i. e. if his hands are on his mouth, then he'll put his hands on his eyes or he'll put his hands on his mouth otherwise. After that, Mike wants to know the score of the bears.

Score of the bears is the maximum over all rows of number of consecutive bears with hands on their eyes in that row.

Since bears are lazy, Mike asked you for help. For each round, tell him the score of these bears after changing the state of a bear selected in that round. 

Input

The first line of input contains three integers n, m and q (1 ≤ n, m ≤ 500 and 1 ≤ q ≤ 5000).

The next n lines contain the grid description. There are m integers separated by spaces in each line. Each of these numbers is either 0 (for mouth) or 1 (for eyes).

The next q lines contain the information about the rounds. Each of them contains two integers i and j (1 ≤ i ≤ n and 1 ≤ j ≤ m), the row number and the column number of the bear changing his state.

Output

After each round, print the current score of the bears.

Examples

Input

5 4 5
0 1 1 0
1 0 0 1
0 1 1 0
1 0 0 1
0 0 0 0
1 1
1 4
1 1
4 2
4 3


Output

3
4
3
3
4

Solution (in JAVA):

Solution:

import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;


public class  bjgldfsghkuldsfhk {

    static class FastScanner{
        BufferedReader s;
        StringTokenizer st;
        
        public FastScanner(){
            st = new StringTokenizer("");
            s = new BufferedReader(new InputStreamReader(System.in));
        }
        
        public FastScanner(File f) throws FileNotFoundException{
            st = new StringTokenizer("");
            s = new BufferedReader (new FileReader(f));
        }
        
        public int nextInt() throws IOException{
            if(st.hasMoreTokens())
                return Integer.parseInt(st.nextToken());
            else{
                st = new StringTokenizer(s.readLine());
                return nextInt();
            }
        }
        
      public double nextDouble() throws IOException{
            if(st.hasMoreTokens())
                return Double.parseDouble(st.nextToken());
            else{
                st = new StringTokenizer(s.readLine());
                return nextDouble();
            }
        }
      
        public long nextLong() throws IOException{
            if(st.hasMoreTokens())
                return Long.parseLong(st.nextToken());
            else{
                st = new StringTokenizer(s.readLine());
                return nextLong();
            }
        }
        
        public String nextString() throws IOException{
            if(st.hasMoreTokens())
                return st.nextToken();
            else{
                st = new StringTokenizer(s.readLine());
                return nextString();
            }
            
        }
        public String readLine() throws IOException{
            return s.readLine();
        }
        
        public void close() throws IOException{
            s.close();
        }
        
    }
     private static FastScanner s = new FastScanner();   
     private static PrintWriter ww = new PrintWriter(new OutputStreamWriter(System.out));
     
      static int count=0;
     public static void main(String[] args) throws IOException 
     {
         int n=s.nextInt();
         int m=s.nextInt();
         int q=s.nextInt();
         int a[][] = new int[n][m];
         int score[] = new int[n];int over=0;int index=0;
         StringBuilder sb = new StringBuilder();
         for(int i=0;i<n;i++)
         {
            
             for(int j=0;j<m;j++)
             {
                 a[i][j]=s.nextInt();
             }
         }
          for(int i=0;i<n;i++)
         {
          int max=0;int ans=0;  
             for(int j=0;j<m;j++)
             {
                 if(a[i][j]!=0)
                 {
                     max+=a[i][j];
                 }
                 else
                     max=0;
                 ans=Math.max(max, ans);
             }
             score[i]=ans;
             if(ans>over)
             {
                 index=i;over=ans;
             }
         }
        
         while(q-->0)
         {
             int i=s.nextInt()-1;int j=s.nextInt()-1;int count=0;
             if(a[i][j]==1)a[i][j]--; else a[i][j]=1;
             int chck=0;int max=0;
             for(int k=0;k<m;k++)
             {
                 if(a[i][k]!=0)
                 {
                     max+=a[i][k];
                 }
                 else
                     max=0;
                 chck=Math.max(max, chck);
             }
             if(i!=index)
             {
                 
                 if(over>chck)
                  {sb.append(over+"\n");score[i]=chck;}
                 else
                 {
                   sb.append(chck+"\n");index=i;over=chck;score[i]=chck;
                 }
             }
             else
             {
                 score[i]=chck;int ans=0;
                 for(int k=0;k<n;k++)
                 {
                    if(score[k]>ans)
                    {
                        ans=score[k];index=k;
                    }
                 }
                 over=ans;
                sb.append(ans+"\n");
             }
         }
         System.out.println(""+sb.toString());
         
         s.close();
         ww.close();
     }
     public static int gcd(int a, int b){
        return b == 0 ? a : gcd(b,a%b);
    }
   
	
}
/*zabardast swappimng of sorting
/*
    Arrays.sort(m, new Comparator<int[]>() {
                        @Override
                        public int compare(int[] int1, int[] int2)
                        {
                            Integer number1 = int1[1];
                            Integer number2 = int2[1];
                            return number1.compareTo(number2);
                        }
                         });
*/
/*
static final Point getMinMax(int[] array) {
		int min = array[0];
		int max = array[0];
		
		for (int index = 0, size = array.length; index < size; ++index, ++index) {
			int value = array[index];
			
			if (index == size - 1) {
				min = min(min, value);
				max = max(max, value);
			} else {
				int otherValue = array[index + 1];
				
				if (value <= otherValue) {
					min = min(min, value);
					max = max(max, otherValue);
				} else {
					min = min(min, otherValue);
					max = max(max, value);
				}
			}
		}
		
		return new Point(min, max);
	}
	
*/
/*

/// Demonstrate several Is... methods.
class IsDemo {
public static void main(String args[]) {
char a[] = {'a', 'b', '5', '?', 'A', ' '};
for(int i=0; i<a.length; i++) {
if(Character.isDigit(a[i]))                                   ///check if digit is present in string
System.out.println(a[i] + " is a digit.");
if(Character.isLetter(a[i]))
    System.out.println(num + " in binary: " +
Integer.toBinaryString(num));
System.out.println(num + " in octal: " +
Integer.toOctalString(num));
System.out.println(num + " in hexadecimal: " +
Integer.toHexString(num));
}
}
*/
/*
private static void findSubsets(int array[])
{
  int numOfSubsets = 1 << array.length; 

  for(int i = 0; i < numOfSubsets; i++)
 {
    int pos = array.length - 1;                                /////bitmask to find all sub sets
   int bitmask = i;

   System.out.print("{");
   while(bitmask > 0)
   {
    if((bitmask & 1) == 1)
     System.out.print(array[pos]+",");
    bitmask >>= 1;
    pos--;
   }
   System.out.print("}");
 }
}
*/

/*   no of DIVISORSSSSSS
 public ArrayList<Integer> get(int x){
            ArrayList<Integer> divisors = new ArrayList<>();
            for(int i = 1; i * i <= x; i++){
                if(x % i == 0){
                    divisors.add(i);
                    if(i * i != x){
                        divisors.add( x / i);
                    }
                }
            }
            
*/
/*  //// find sum of multiple of a value below limit// ----> (l*(n+1))/2
  public static long getSequenceSum(long value, long limit) {
long q = (limit - 1) / value;
long ans = ((value*q)*(1+q) )/ 2;
return ans;
}
*/
/*// largest prime factor of a no
 public static long largestPrimeFactor(long n) {

        // largest composite factor must be smaller than sqrt
        long sqrt = (long)Math.ceil(Math.sqrt((double)n));

        long largest = -1;

        for(long i = 2; i <= sqrt; i++) {
            if(n % i == 0) {
                long test = largestPrimeFactor(n/i);
                if(test > largest) {
                    largest = test;
                }
            }
        }

        if(largest != -1) {
            return largest;
        }

        // number is prime
        return n;
    } 
*/
/*    // prime no using sieve of erostheneses
  public static void prime()
{
  boolean[] isPrime = new boolean[100000000+ 1];
         Arrays.fill(isPrime, true);

        // mark non-primes <= N using Sieve of Eratosthenes
        for (int i = 2; i*i <= 100000000; i++)
        {

             if (isPrime[i])
             {
                for (int j = i; i*j <= 100000000; j++) {
                    isPrime[i*j] = false;
                }
            }
        }
}

*/
/*//// largest common sequences
 public String lcs(String str1, String str2)
    {
        int l1 = str1.length();
        int l2 = str2.length();
 
        int[][] arr = new int[l1 + 1][l2 + 1];
 
        for (int i = l1 - 1; i >= 0; i--)
        {
            for (int j = l2 - 1; j >= 0; j--)
            {
                if (str1.charAt(i) == str2.charAt(j))
                    arr[i][j] = arr[i + 1][j + 1] + 1;
                else 
                    arr[i][j] = Math.max(arr[i + 1][j], arr[i][j + 1]);
            }
        }
 
        int i = 0, j = 0;
        StringBuffer sb = new StringBuffer();
        while (i < l1 && j < l2) 
     
 {
            if (str1.charAt(i) == str2.charAt(j)) 
            {
                sb.append(str1.charAt(i));
                i++;
                j++;
            }
            else if (arr[i + 1][j] >= arr[i][j + 1]) 
                i++;
            else
                j++;
        }
        return sb.toString();
    }
 
*/