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.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.*;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;


public class Main {
	static int n, m;
	static int v[][] = new int[502][502];
	static int id[][] = new int[502][502];
	static TreeSet<Segmento> set;
	static int tam_seg[] = new int [500 * 500 + 5000 +10];
	public static void main(String args[]) {
		InputReader in = new InputReader(System.in);
        PrintWriter out = new PrintWriter(System.out);
        n = in.nextInt();
        m = in.nextInt();
        int q;
        q = in.nextInt();
        for (int i = 1; i <= n; i++)
			for (int j = 1; j <= m; j++)
				v[i][j] = in.nextInt();
		int next_id = 0;
		set = new TreeSet<Segmento>(new CompareSegmento());
		int tam = 0;
		for (int i = 1; i <= n; i++) {
			Arrays.fill(id[i], -1);
			for (int j = 1; j <= m; j++)
				if (v[i][j] == 1) {
					if (v[i][j - 1] == 0) {
						if (next_id != 0) {
							set.add(new Segmento(tam, next_id - 1));
							tam_seg[next_id - 1] = tam;
						}
						id[i][j] = next_id++;
						tam = 1;
					} else {
						id[i][j] = id[i][j - 1];
						tam++;
					}
				}
		}
		if (tam > 0) {
			set.add(new Segmento(tam, next_id - 1));
			tam_seg[next_id - 1] = tam;
		}
				
        for (int qq = 0; qq < q; qq++) {
			int i = in.nextInt();
			int j = in.nextInt();
			if (v[i][j] == 0) {//se convertira en 1
				v[i][j] = 1;
				boolean izq = (v[i][j - 1] == 1);
				boolean der = (v[i][j + 1] == 1);
				if (izq && der) {//une dos segmentos
					int idizq = id[i][j - 1];
					int idder = id[i][j + 1];
					set.remove(new Segmento(tam_seg[idizq], idizq));
					set.remove(new Segmento(tam_seg[idder], idder));
					set.add(new Segmento(tam_seg[idizq] + tam_seg[idder] + 1, idizq));
					tam_seg[idizq] = tam_seg[idizq] + tam_seg[idder] + 1;
					id[i][j] = idizq;
					for (int k = 1; k <= m; k++)
						if (id[i][k] == idder)
							id[i][k] = idizq;
				} else if (izq) {
					int idizq = id[i][j - 1];
					set.remove(new Segmento(tam_seg[idizq], idizq));
					set.add(new Segmento(tam_seg[idizq] + 1, idizq));
					tam_seg[idizq] = tam_seg[idizq] + 1;
					id[i][j] = idizq;
				} else if (der) {
					int idder = id[i][j + 1];
					set.remove(new Segmento(tam_seg[idder], idder));
					set.add(new Segmento(tam_seg[idder] + 1, idder));
					tam_seg[idder] = tam_seg[idder] + 1;
					id[i][j] = idder;
				} else {
					set.add(new Segmento(1, next_id));
					tam_seg[next_id] = 1;
					id[i][j] = next_id++;
				}
			} else {// se convertira en 0
				v[i][j] = 0;
				boolean izq = (v[i][j - 1] == 1);
				boolean der = (v[i][j + 1] == 1);
				if (izq && der) {//se separan dos segmentos
					int idizq = id[i][j - 1];
					set.remove(new Segmento(tam_seg[idizq], idizq));
					int cntizq = 0;
					for (int k = j - 1; k >= 1; k--)
						if (id[i][k] == idizq)
							cntizq++;
					int cntder = tam_seg[idizq] - cntizq - 1;
					
					set.add(new Segmento(cntizq, idizq));
					set.add(new Segmento(cntder, next_id));
					
					tam_seg[idizq] = cntizq;
					tam_seg[next_id] = cntder;
					
					id[i][j] = -1;
					for (int k = j + 1; k <= m; k++)
						if (id[i][k] == idizq)
							id[i][k] = next_id;
					next_id++;
				} else if (izq) {
					int idizq = id[i][j - 1];
					set.remove(new Segmento(tam_seg[idizq], idizq));
					set.add(new Segmento(tam_seg[idizq] - 1, idizq));
					tam_seg[idizq] = tam_seg[idizq] - 1;
					id[i][j] = -1;
				} else if (der) {
					int idder = id[i][j + 1];
					set.remove(new Segmento(tam_seg[idder], idder));
					set.add(new Segmento(tam_seg[idder] - 1, idder));
					tam_seg[idder] = tam_seg[idder] - 1;
					id[i][j] = -1;
				} else {
					set.remove(new Segmento(1, id[i][j]));
					tam_seg[id[i][j]] = 0;
					id[i][j] = -1;
				}
			}
			if (set.size() == 0)
				out.println(0);
			else
				out.println(set.last().tam);
		}
        out.close();
	}
	static class Segmento {
		int tam, id;
		Segmento() {
			this.tam = 0;
			this.id = -1;
		}
		Segmento(int _tam, int _id) {
			this.tam = _tam;
			this.id = _id;
		}
		
		public String toString() {
			return "("+tam+", "+id+")";
		}
	}
	static class CompareSegmento implements Comparator<Segmento>  {
		@Override
		public int compare(Segmento a, Segmento b) {
			if (a.tam != b.tam)
				return (a.tam < b.tam)?-1: 1;
			if (a.id != b.id)
				return (a.id < b.id)?-1: 1;
			return 0;
		}
	}
	static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }
        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }
        public int nextInt() {
            return Integer.parseInt(next());
        }
    }
}