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

Difficulty: MEDIUM
Tags: Dynamic programming

Complete search

Implementation

Greedy algorithms
Skill types: Dynamic programming

Complete search

Greedy algorithms

Starter code:

Solutions:
(rows, cols, changes_count) = map(int, input().split())
grid = [input().split() for _ in range(rows)]
changes = [map(int, input().split()) for __ in range(changes_count)]
max_line = [max(map(len, ''.join(row).split('0'))) for row in grid]
for (r, c) in changes:
	grid[r - 1][c - 1] = '0' if grid[r - 1][c - 1] == '1' else '1'
	max_line[r - 1] = max(map(len, ''.join(grid[r - 1]).split('0')))
	print(max(max_line))


def conta(mat):
	combo = 0
	maior = 0
	for l in range(len(mat)):
		if mat[l] == 1:
			combo += 1
		elif combo > 0:
			if combo > maior:
				maior = combo
			combo = 0
	if combo > maior:
		maior = combo
	return maior
(i, j, t) = [int(z) for z in input().split(' ')]
matriz = []
M = []
for i1 in range(i):
	valor = [int(z) for z in input().split(' ')]
	matriz.append(valor)
	M.append(conta(valor))
cpy = matriz[:]
for q in range(t):
	(n, m) = [int(z) for z in input().split(' ')]
	if cpy[n - 1][m - 1] == 1:
		cpy[n - 1][m - 1] = 0
	else:
		cpy[n - 1][m - 1] = 1
	tes = conta(cpy[n - 1])
	M[n - 1] = tes
	print(max(M))


def conseqones(a):
	maximum = 0
	index = 0
	while index < len(a):
		if a[index] == 1:
			curcount = 1
			index += 1
			while index < len(a) and a[index] == 1:
				index += 1
				curcount += 1
			if curcount > maximum:
				maximum = curcount
		else:
			index += 1
	return maximum

def findmaxrow(a):
	maximum = 0
	maxindex = 0
	for i in range(len(a)):
		cur = conseqones(a[i])
		if cur > maximum:
			maximum = cur
			maxindex = i
	return (maximum, maxindex)
thelist = input().split()
r = int(thelist[0])
c = int(thelist[1])
q = int(thelist[2])
a = [[0 for i in range(c)] for j in range(r)]
for i in range(r):
	therow = input().split()
	for j in range(c):
		a[i][j] = int(therow[j])
curmax = findmaxrow(a)[0]
curmaxindex = findmaxrow(a)[1]
for i in range(q):
	coord = input().split()
	x = int(coord[0]) - 1
	y = int(coord[1]) - 1
	a[x][y] = 1 - a[x][y]
	newone = conseqones(a[x])
	if newone >= curmax:
		curmax = newone
		curmaxindex = x
		print(newone)
	elif x == curmaxindex:
		curmax = findmaxrow(a)[0]
		curmaxindex = findmaxrow(a)[1]
		print(curmax)
	else:
		print(curmax)


def func(a):
	s = 0
	per = 0
	for i in range(len(a)):
		if a[i] == '1':
			per += 1
		else:
			s = max(s, per)
			per = 0
	s = max(per, s)
	return s

def main(a):
	A = []
	B = [0] * int(a[0])
	for i in range(int(a[0])):
		A.append(input().split())
	for i in range(int(a[0])):
		B[i] = func(A[i])
	for i in range(int(a[2])):
		s = 0
		k = input().split()
		A[int(k[0]) - 1][int(k[1]) - 1] = str((int(A[int(k[0]) - 1][int(k[1]) - 1]) + 1) % 2)
		B[int(k[0]) - 1] = func(A[int(k[0]) - 1])
		for i in B:
			s = max(s, i)
		print(s)
a = input().split()
main(a)


from functools import reduce
from operator import *
from math import *
from sys import setrecursionlimit
setrecursionlimit(10 ** 7)
(n, m, q) = map(int, input().split())
grid = [0] * n
maxCnt = [0] * n

def cntmax1(seq):
	maxcnt = 0
	cnt = 0
	for i in seq:
		if i == 1:
			cnt += 1
		else:
			cnt = 0
		maxcnt = max(cnt, maxcnt)
	return maxcnt
for i in range(n):
	grid[i] = list(map(int, input().split()))
	maxCnt[i] = cntmax1(grid[i])
for i in range(q):
	(x, y) = map(int, input().split())
	x -= 1
	y -= 1
	grid[x][y] ^= 1
	maxCnt[x] = cntmax1(grid[x])
	print(max(maxCnt))


(n, m, q) = map(int, input().split(' '))
a = []

def cons_ones(l, m):
	ans = 0
	c = 0
	for i in range(m):
		if l[i] == 1:
			c += 1
		else:
			ans = max(ans, c)
			c = 0
	ans = max(ans, c)
	return ans
anss = []
for i in range(n):
	s = list(map(int, input().split(' ')))
	anss.append(cons_ones(s, m))
	a.append(s)
for i in range(q):
	(x, y) = map(int, input().split(' '))
	x -= 1
	y -= 1
	if a[x][y]:
		a[x][y] = 0
	else:
		a[x][y] = 1
	anss[x] = cons_ones(a[x], m)
	print(max(anss))


(n, m, q) = map(int, input().split())
hor = [0] * n
table = [0] * n
for i in range(n):
	table[i] = list(map(int, input().split()))
for h in range(n):
	tmp = 0
	for v in range(m):
		if table[h][v]:
			tmp += 1
		else:
			if hor[h] < tmp:
				hor[h] = tmp
			tmp = 0
	if hor[h] < tmp:
		hor[h] = tmp
tmp = 0
for qu in range(q):
	(i, j) = tuple(map(int, input().split()))
	i -= 1
	j -= 1
	table[i][j] = 0 if table[i][j] else 1
	hor[i] = 0
	for v in range(m):
		if table[i][v]:
			tmp += 1
		else:
			if hor[i] < tmp:
				hor[i] = tmp
			tmp = 0
	if hor[i] < tmp:
		hor[i] = tmp
	tmp = 0
	print(max(hor))


r = lambda : input().split()
g = lambda s: max(map(len, ''.join(s).split('0')))
(n, m, q) = map(int, r())
a = [r() for _ in range(n)]
b = list(map(g, a))
for _ in range(q):
	(x, y) = map(int, r())
	a[x - 1][y - 1] = str(1 - int(a[x - 1][y - 1]))
	b[x - 1] = g(a[x - 1])
	print(max(b))


from sys import stdin

def input():
	return stdin.readline().rstrip()

def calcMax(a):
	ret = cur = 0
	for (i, v) in enumerate(a):
		if v == 1:
			cur += 1
		else:
			cur = 0
		ret = max(ret, cur)
	return ret
(sizeI, sizeJ, nQ) = map(int, input().split())
a = [list(map(int, input().split())) for _ in range(sizeI)]
ret = []
cnt = [calcMax(r) for r in a]
for _ in range(nQ):
	(i, j) = map(lambda x: int(x) - 1, input().split())
	a[i][j] ^= 1
	cnt[i] = calcMax(a[i])
	ret.append('%d' % max(cnt))
print('\n'.join(ret))


(n, m, q) = map(int, input().split())
(ms, kk) = ([], [])
mp = ms.append
kkp = kk.append
for i in range(n):
	mp(list(map(int, input().split())))
	(l, mm) = (0, 0)
	for j in range(m):
		if ms[i][j]:
			l += 1
		else:
			if l > mm:
				mm = l
			l = 0
	if l > mm:
		mm = l
	kkp(mm)
for i in range(q):
	(y, x) = map(lambda x: int(x) - 1, input().split())
	(mm, ms[y][x], l) = (0, 1 - ms[y][x], 0)
	for j in range(m):
		if ms[y][j]:
			l += 1
		else:
			if l > mm:
				mm = l
			l = 0
	if l > mm:
		mm = l
	kk[y] = mm
	mm = 0
	for ii in kk:
		mm = max(mm, ii)
	print(mm)


(n, m, q) = map(int, input().split())
F = [list(map(int, input().split())) for i in range(n)]

def calc(i):
	ans = 0
	l = -1
	for j in range(m):
		if F[i][j] == 0:
			l = j
		else:
			ans = max(ans, j - l)
	return ans
row = list(map(calc, range(n)))
for i in range(q):
	(y, x) = map(int, input().split())
	y -= 1
	x -= 1
	F[y][x] = 1 - F[y][x]
	row[y] = calc(y)
	print(max(row))


import sys
input = []
input_index = 0

def next(type, number=None):

	def next():
		global input, input_index
		if input_index == len(input):
			if sys.stdin:
				input = sys.stdin.readline().split()
				input_index = 0
			else:
				raise Exception()
		input_index += 1
		return input[input_index - 1]
	if number is None:
		result = type(next())
	else:
		result = [type(next()) for _ in range(number)]
	return result
(n, m, q) = next(int, 3)
fs = [next(int, m) for _ in range(n)]

def get_m(i):
	m = 0
	c = 0
	for f in fs[i]:
		if f:
			c += 1
		else:
			m = max(m, c)
			c = 0
	m = max(m, c)
	return m
ms = [get_m(i) for i in range(n)]
for _ in range(q):
	(i, j) = next(int, 2)
	(i, j) = (i - 1, j - 1)
	fs[i][j] ^= 1
	ms[i] = get_m(i)
	print(max(ms))


(n, m, q) = map(int, input().split())
a = [[]]
for i in range(n):
	a.append([0] + list(map(int, input().split())))
(x, y) = map(int, input().split())
a[x][y] = (a[x][y] + 1) % 2
ma = 0
curr = 0
for i in range(1, n + 1):
	for j in range(1, m + 1):
		if a[i][j] == 0:
			ma = max(curr, ma)
			curr = 0
		else:
			curr += 1
	ma = max(ma, curr)
	curr = 0
res = 0
for i in range(1, n + 1):
	for j in range(1, m + 1):
		if a[i][j] == 0:
			if curr == ma:
				res += 1
			curr = 0
		else:
			curr += 1
	if curr == ma:
		res += 1
	curr = 0
print(ma)
for i in range(q - 1):
	(x, y) = map(int, input().split())
	if a[x][y] == 1:
		j = y - 1
		here = 1
		while j >= 0 and a[x][j] == 1:
			j -= 1
			here += 1
		j = y + 1
		while j <= m and a[x][j] == 1:
			j += 1
			here += 1
		a[x][y] = 0
		if here == ma:
			res -= 1
		if res >= 1:
			print(ma)
		else:
			ma = 0
			curr = 0
			for i in range(1, n + 1):
				for j in range(1, m + 1):
					if a[i][j] == 0:
						ma = max(curr, ma)
						curr = 0
					else:
						curr += 1
				ma = max(ma, curr)
				curr = 0
			res = 0
			for i in range(1, n + 1):
				for j in range(1, m + 1):
					if a[i][j] == 0:
						if curr == ma:
							res += 1
						curr = 0
					else:
						curr += 1
				if curr == ma:
					res += 1
				curr = 0
			print(ma)
	else:
		a[x][y] = 1
		j = y - 1
		here = 1
		while j >= 0 and a[x][j] == 1:
			j -= 1
			here += 1
		j = y + 1
		while j <= m and a[x][j] == 1:
			j += 1
			here += 1
		if here > ma:
			ma = here
			res = 1
		elif here == ma:
			res += 1
		print(ma)


import math, string, itertools, fractions, heapq, collections, re, array, bisect
from itertools import chain, dropwhile, permutations, combinations
from collections import defaultdict

def VI():
	return list(map(int, input().split()))

def get_score(x):
	b = 0
	best = 0
	running = 0
	for (i, v) in enumerate(x):
		if v == 1:
			if running:
				b += 1
			else:
				b = 1
			running = 1
		else:
			if running:
				if b > best:
					best = b
			running = 0
	if b > best:
		best = b
	return best

def main_input(info=0):
	(n, m, q) = VI()
	g = list(range(n))
	sc = list(range(n))
	for i in range(n):
		g[i] = VI()
		sc[i] = get_score(g[i])
	r = list(range(q))
	for k in range(q):
		(i, j) = VI()
		(i, j) = (i - 1, j - 1)
		g[i][j] = 1 - g[i][j]
		sc[i] = get_score(g[i])
		print(max(sc))
main_input()


import re

def maxString(a, i, n):
	s2 = ''.join(a[i])
	if '1' not in s2:
		return 0
	r = len(max(re.findall('1+', s2), key=len))
	return r

def flip(x):
	if x == '1':
		return '0'
	else:
		return '1'
(n, m, q) = map(int, input().split())
a = []
x = []
for i in range(n):
	x = list(input().split())
	a.append(x)
y = []
for i in range(n):
	y.append(maxString(a, i, n))
z = max(y)
r = y.index(z)
for i in range(q):
	(x1, y1) = map(int, input().split())
	a[x1 - 1][y1 - 1] = flip(a[x1 - 1][y1 - 1])
	y[x1 - 1] = maxString(a, x1 - 1, n)
	z = max(y)
	print(z)


f = lambda s: max(map(len, ''.join(s).split('0')))
(n, m, q) = map(int, input().split())
a = [input().split() for i in range(n)]
b = list(map(f, a))
c = [list(map(int, input().split())) for i in range(q)]
for (x, y) in c:
	a[x - 1][y - 1] = str(1 - int(a[x - 1][y - 1]))
	b[x - 1] = f(a[x - 1])
	print(max(b))


from sys import stdin

def counter(num):
	if num == 0:
		return 1
	else:
		return 0

def find_max(arr):
	mx = 0
	temp = 0
	for i in range(len(arr)):
		if temp >= 1:
			if arr[i] == 0:
				temp = 0
			else:
				temp += 1
		elif arr[i] == 1:
			temp = 1
		elif arr[i] == 0:
			temp = 0
		mx = max(temp, mx)
	return mx

def get_it(matrix):
	aux = []
	for i in range(n):
		aux.append(find_max(matrix[i]))
	return aux
(n, m, q) = list(map(int, stdin.readline().split()))
matrix = []
for _ in range(n):
	matrix.append(list(map(int, stdin.readline().split())))
con_eye = get_it(matrix)
for _ in range(q):
	(i, j) = list(map(int, stdin.readline().split()))
	i -= 1
	j -= 1
	matrix[i][j] = counter(matrix[i][j])
	con_eye[i] = find_max(matrix[i])
	print(max(con_eye))


def cons(l):
	m = 0
	res = 0
	for v in l:
		if v:
			res += 1
			if res > m:
				m = res
		else:
			res = 0
	return m
(n, m, q) = map(int, input().split())
grid = []
curr = [0] * n
for i in range(n):
	grid.append(list(map(int, input().split())))
	curr[i] = cons(grid[i])
for _ in range(q):
	(i, j) = map(int, input().split())
	i -= 1
	j -= 1
	grid[i][j] = 0 if grid[i][j] else 1
	curr[i] = cons(grid[i])
	print(max(curr))


import pprint

def getRow(row):
	m = 0
	cur = 0
	for v in row:
		if v == 1:
			cur += 1
			if cur > m:
				m = cur
		else:
			cur = 0
	return m
(n, m, k) = list(map(int, input().split()))
a = []
v = [0 for i in range(n)]
for i in range(n):
	tmp = list(map(int, input().split()))
	v[i] = getRow(tmp)
	a.append(tmp)
for test in range(k):
	(i, j) = list(map(int, input().split()))
	i -= 1
	j -= 1
	if a[i][j] == 0:
		a[i][j] = 1
	else:
		a[i][j] = 0
	v[i] = getRow(a[i])
	print(max(v))


(n, m, q) = map(int, input().split(' ')[:3])
entry_idx = 1

class Entry:

	def __init__(self, m, M):
		global entry_idx
		self._min = m
		self._max = M

	def __str__(self):
		return '[' + str(self._min) + '-' + str(self._max) + ']'

	def __len__(self):
		return self._max - self._min + 1
lines = []
maxes = []
for _ in range(n):
	linec = input().split(' ')
	line = []
	entry = None
	max_line = 0
	for i in range(m):
		c = linec[i]
		if c == '1':
			if entry:
				entry._max = i
			else:
				entry = Entry(i, i)
			if len(entry) > max_line:
				max_line = len(entry)
		else:
			entry = None
		line.append(entry)
	lines.append(line)
	maxes.append(max_line)
for _ in range(q):
	(i, j) = map(int, input().split(' ')[:2])
	i -= 1
	j -= 1
	line = lines[i]
	entry = line[j]
	if entry:
		line[j] = None
		e_left = Entry(entry._min, j - 1)
		entry._min = j + 1
		j -= 1
		while j >= 0 and line[j] is entry:
			line[j] = e_left
			j -= 1
		M = 0
		for e in line:
			if e and len(e) > M:
				M = len(e)
		maxes[i] = M
	else:
		entry = Entry(j, j)
		line[j] = entry
		if j > 0 and line[j - 1]:
			e_to_replace = line[j - 1]
			entry._min = e_to_replace._min
			jj = j - 1
			while jj >= 0 and line[jj] is e_to_replace:
				line[jj] = entry
				jj -= 1
		if j < m - 1 and line[j + 1]:
			e_to_replace = line[j + 1]
			entry._max = e_to_replace._max
			jj = j + 1
			while jj < m and line[jj] is e_to_replace:
				line[jj] = entry
				jj += 1
		if len(entry) > maxes[i]:
			maxes[i] = len(entry)
	print(max(maxes))


def score(arr):
	n = len(arr)
	max_ = 0
	curr = 0
	for i in range(n):
		if arr[i] == 1:
			curr += 1
		else:
			curr = 0
		max_ = max(max_, curr)
	return max_
(n, m, q) = map(int, input().split())
a = []
for _ in range(n):
	a.append([int(i) for i in input().split()])
m = {}
for i in range(n):
	m[i] = score(a[i])
for _ in range(q):
	(i, j) = map(int, input().split())
	i -= 1
	j -= 1
	a[i][j] = 1 - a[i][j]
	m[i] = score(a[i])
	print(max(m.values()))


(n, m, q) = [int(x) for x in input().split()]
x = [[int(x) for x in input().split()] + [0] for _ in range(n)]
s = [1, 0]
l = []
for i in range(n):
	z = 0
	p = 0
	for j in range(m + 1):
		if x[i][j] == 1:
			p += 1
		else:
			z = max(z, p)
			p = 0
	l.append(z)
for _ in range(q):
	(a, b) = [int(x) for x in input().split()]
	x[a - 1][b - 1] = s[x[a - 1][b - 1]]
	p = 0
	z = 0
	for j in range(m + 1):
		if x[a - 1][j] == 1:
			p += 1
		else:
			z = max(z, p)
			p = 0
	l[a - 1] = z
	print(max(l))


import sys
import os
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
mod = 10 ** 9 + 7

def lcm(x, y):
	return x * y / gcd(x, y)

def fact(x, mod=mod):
	ans = 1
	for i in range(1, x + 1):
		ans = ans * i % mod
	return ans

def arr2D(n, m, default=0):
	return [[default for j in range(m)] for i in range(n)]

def arr3D(n, m, r, default=0):
	return [[[default for k in range(r)] for j in range(m)] for i in range(n)]

def sortDictV(x):
	return {k: v for (k, v) in sorted(x.items(), key=lambda item: item[1])}

class DSU:

	def __init__(self, length):
		self.length = length
		self.parent = [-1] * self.length

	def getParent(self, node, start):
		if node >= self.length:
			return False
		if self.parent[node] < 0:
			if start != node:
				self.parent[start] = node
			return node
		return self.getParent(self.parent[node], start)

	def union(self, node1, node2):
		parent1 = self.getParent(node1, node1)
		parent2 = self.getParent(node2, node2)
		if parent1 == parent2:
			return False
		elif self.parent[parent1] <= self.parent[parent2]:
			self.parent[parent1] += self.parent[parent2]
			self.parent[parent2] = parent1
		else:
			self.parent[parent2] += self.parent[parent1]
			self.parent[parent1] = parent2
		return True

	def getCount(self, node):
		return -self.parent[self.getParent(node, node)]

def solve(n, m, q, lst, moves):
	for i in lst:
		i.append(0)
	rowMaxx = []
	for i in range(n):
		maxx = 0
		ones = 0
		for j in range(m + 1):
			if lst[i][j] == 0:
				maxx = max(maxx, ones)
				ones = 0
			else:
				ones += 1
		rowMaxx.append(maxx)
	for i in moves:
		lst[i[0] - 1][i[1] - 1] = 1 - lst[i[0] - 1][i[1] - 1]
		ones = 0
		rowMaxx[i[0] - 1] = 0
		for j in lst[i[0] - 1]:
			if j == 0:
				rowMaxx[i[0] - 1] = max(rowMaxx[i[0] - 1], ones)
				ones = 0
			else:
				ones += 1
		print(max(rowMaxx))
(n, m, q) = list(map(int, input().split()))
lst = []
for i in range(n):
	lst.append(list(map(int, input().split())))
moves = []
for i in range(q):
	moves.append(list(map(int, input().split())))
solve(n, m, q, lst, moves)


def condMax(row):
	flag = False
	(ret, cnt) = (0, 0)
	for x in row:
		if flag == False and x == 1:
			cnt = 1
			flag = True
		elif flag == True and x == 1:
			cnt += 1
		elif flag == True and x == 0:
			ret = max(cnt, ret)
			flag = False
	if flag == True:
		ret = max(cnt, ret)
	return ret
(N, M, Q) = map(int, input().split())
board = [list(map(int, input().split())) for _ in range(N)]
rows = [condMax(row[:]) for row in board]
ans = max(rows)
for i in range(Q):
	(i, j) = map(lambda x: int(x) - 1, input().split())
	board[i][j] ^= 1
	rows[i] = condMax(board[i][:])
	ans = max(rows)
	print(ans)


(n, m, q) = input().split()
n = int(n)
m = int(m)
q = int(q)
(l, p) = ([], [])

def su(l):
	l1 = len(l)
	i = 0
	hig = 0
	while i < l1:
		j = i
		s1 = 0
		while j < l1:
			if l[j] == 1:
				s1 += 1
			else:
				break
			j += 1
		i = j + 1
		if hig < s1:
			hig = s1
	return hig
for i in range(n):
	l1 = input().split()
	for j in range(m):
		l1[j] = int(l1[j])
	l.append(l1)
	p.append(su(l1))
for i in range(q):
	(x, y) = input().split()
	x = int(x) - 1
	y = int(y) - 1
	high = 0
	l[x][y] = 1 - l[x][y]
	p[x] = su(l[x])
	for i in range(n):
		if high < p[i]:
			high = p[i]
	print(high)


(n, m, q) = [int(x) for x in input().split()]
data = []
saveCount = []
globalMax = 0
globalMaxIndex = -1
for i in range(n):
	temp = [int(x) for x in input().split()]
	mx = 0
	curEyes = 0
	for j in range(m):
		if temp[j] == 1:
			curEyes += 1
			if curEyes > mx:
				mx = curEyes
		else:
			curEyes = 0
	saveCount.append(mx)
	if mx > globalMax:
		globalMaxIndex = i
		globalMax = mx
	data.append(temp)
for i in range(q):
	(y, x) = [int(c) - 1 for c in input().split()]
	data[y][x] = 0 if data[y][x] else 1
	mx = 0
	curEyes = 0
	if y == globalMaxIndex:
		saveCount[y] = 0
		globalMax = 0
		for j in range(n):
			if saveCount[j] > globalMax:
				globalMax = saveCount[j]
				globalMaxIndex = j
	for j in range(m):
		if data[y][j] == 1:
			curEyes += 1
			if curEyes > mx:
				mx = curEyes
		else:
			curEyes = 0
	if mx > globalMax:
		print(mx)
		globalMax = mx
		globalMaxIndex = y
	else:
		print(globalMax)
	saveCount[y] = mx


R = lambda : map(int, input().split())
(n, m, q) = R()
g = [0] * n
mr = [0] * n
for i in range(n):
	g[i] = list(R())
	tres = 0
	for j in range(m):
		if g[i][j] == 1:
			tres += 1
		else:
			tres = 0
		mr[i] = max(mr[i], tres)
for _ in range(q):
	(i, j) = R()
	(i, j) = (i - 1, j - 1)
	g[i][j] = 1 - g[i][j]
	tres = 0
	mr[i] = 0
	for k in range(m):
		if g[i][k] == 1:
			tres += 1
		else:
			tres = 0
		mr[i] = max(mr[i], tres)
	print(max(mr))


ml = lambda s: max(map(len, ''.join(s).split('0')))
(n, m, q) = map(int, input().split())
l = [0] * n
mat = list()
for i in range(n):
	z = list(input().split())
	mat.append(z)
	l[i] = ml(z)
for i in range(q):
	(a, b) = map(int, input().split())
	a -= 1
	b -= 1
	mat[a][b] = str(1 - int(mat[a][b]))
	l[a] = ml(mat[a])
	score = max(l)
	print(score)


(n, m, q) = map(int, input().split())

def csum(row):
	return max(map(len, row.split('0')))
grid = [''.join(input().split()) for i in range(n)]
score = [max(map(len, row.split('0'))) for row in grid]
for i in range(q):
	(i, j) = map(int, input().split())
	row = grid[i - 1]
	row = row[:j - 1] + ('1' if row[j - 1] == '0' else '0') + row[j:]
	grid[i - 1] = row
	score[i - 1] = csum(row)
	print(max(score))


from sys import stdin, stdout
nmbr = lambda : int(stdin.readline())
lst = lambda : list(map(int, stdin.readline().split()))

def fn(row):
	cnt = res = 0
	for j in range(c):
		if a[row][j] == 1:
			cnt += 1
		else:
			cnt = 0
		res = max(cnt, res)
	return res
for _ in range(1):
	(r, c, q) = lst()
	a = [lst() for _ in range(r)]
	l = [fn(i) for i in range(r)]
	for _ in range(q):
		(x, y) = lst()
		a[x - 1][y - 1] ^= 1
		cnt = res = 0
		for j in range(c):
			if a[x - 1][j] == 1:
				cnt += 1
			else:
				cnt = 0
			res = max(cnt, res)
		l[x - 1] = res
		print(max(l))


string = input()
(a, b, n) = map(int, string.split())
rows = [list(map(int, input().split())) for x in range(a)]

def streak(y):
	streaks = []
	s = 0
	for x in y:
		if x == 0:
			streaks.append(s)
			s = 0
		else:
			s += 1
	streaks.append(s)
	return max(streaks)
bears = [streak(x) for x in rows]
scores = []
for x in range(n):
	string = input()
	numbers = string.split()
	(p, q) = (int(numbers[0]) - 1, int(numbers[1]) - 1)
	if rows[p][q] == 0:
		rows[p][q] = 1
	else:
		rows[p][q] = 0
	bears[p] = streak(rows[p])
	scores.append(max(bears))
for x in scores:
	print(x)


def count_max(start, finish):
	mx = 0
	pos = 0
	for i in range(start, finish):
		s = ''.join(a[i])
		s = s.split('0')
		for j in s:
			l = len(j)
			if l > mx:
				mx = l
				pos = i
	return (mx, pos)

def count(c, d):
	v = 0
	t = d
	while t != -1 and a[c][t] == '1':
		v += 1
		t -= 1
	t = d
	while t != m and a[c][t] == '1':
		v += 1
		t += 1
	if a[c][d] == '1':
		v -= 1
	return v
(n, m, q) = map(int, input().split())
a = []
for i in range(n):
	a.append(input().split())
(mx, pos) = count_max(0, n)
for i in range(q):
	(c, d) = map(int, input().split())
	c -= 1
	d -= 1
	a[c][d] = str(1 - int(a[c][d]))
	if c == pos:
		(mx, pos) = count_max(0, n)
	else:
		v = count(c, d)
		if v > mx:
			mx = v
			pos = c
	print(mx)


(n, m, q) = map(int, input().split())
a = [0] * n
ans = [0] * n
for i in range(0, n):
	s = list(map(int, input().split()))
	for j in range(0, m):
		a[i] = s
for i in range(n):
	max_1 = 0
	curr = 0
	for j in range(m):
		if a[i][j] == 0:
			curr = 0
		else:
			curr += 1
			max_1 = max(curr, max_1)
	ans[i] = max_1
for x in range(q):
	(x, y) = map(int, input().split())
	if a[x - 1][y - 1] == 0:
		a[x - 1][y - 1] = 1
	else:
		a[x - 1][y - 1] = 0
	curr = 0
	max_1 = 0
	for j in range(m):
		if a[x - 1][j] == 0:
			curr = 0
		else:
			curr += 1
			max_1 = max(curr, max_1)
	ans[x - 1] = max_1
	print(max(ans))


import sys

def fastio():
	from io import StringIO
	from atexit import register
	global input
	sys.stdin = StringIO(sys.stdin.read())
	input = lambda : sys.stdin.readline().rstrip('\r\n')
	sys.stdout = StringIO()
	register(lambda : sys.__stdout__.write(sys.stdout.getvalue()))
fastio()

def debug(*var, sep=' ', end='\n'):
	print(*var, file=sys.stderr, end=end, sep=sep)
INF = 10 ** 20
MOD = 10 ** 9 + 7
I = lambda : list(map(int, input().split()))
from math import ceil
from collections import defaultdict as dd, Counter
from bisect import bisect_left as bl, bisect_right as br
(n, m, q) = I()
ans = [0] * n
matrix = []
for i in range(n):
	a = I()
	cur = 0
	matrix.append(a)
	for j in range(m):
		if a[j] == 1:
			cur += 1
		else:
			cur = 0
		ans[i] = max(ans[i], cur)
while q:
	q -= 1
	(x, y) = I()
	x -= 1
	y -= 1
	matrix[x][y] ^= 1
	ans[x] = 0
	cur = 0
	for j in range(m):
		if matrix[x][j] == 1:
			cur += 1
		else:
			cur = 0
		ans[x] = max(ans[x], cur)
	print(max(ans))


import time

def res(row):
	ans = 0
	buf = 0
	for i in row:
		if i == 1:
			buf += 1
		elif buf != 0:
			ans = max(ans, buf)
			buf = 0
	ans = max(ans, buf)
	return ans
(n, m, q) = (int(i) for i in input().split())
desk = []
score = []
start = time.time()
for j in range(n):
	row = [int(i) for i in input().split()]
	desk.append(row)
	score.append(res(row))
ans = []
for k in range(q):
	(i, j) = (int(l) for l in input().split())
	i -= 1
	j -= 1
	desk[i][j] = 1 if desk[i][j] == 0 else 0
	score[i] = res(desk[i])
	ans.append(max(score))
for i in ans:
	print(i)
finish = time.time()


(n, m, q) = map(int, input().split())
grid = [] * m
for i in range(n):
	grid.append(list(map(int, input().split())))
count = []
for i in range(n):
	c = 0
	tmp = 0
	for j in range(m):
		if grid[i][j] == 1:
			c += 1
		else:
			tmp = max(c, tmp)
			c = 0
	count.append(max(tmp, c))
for i in range(q):
	(x, y) = map(int, input().split())
	x -= 1
	y -= 1
	if grid[x][y] == 0:
		grid[x][y] = 1
	else:
		grid[x][y] = 0
	c = tmp = 0
	for i in range(m):
		if grid[x][i] == 1:
			c += 1
		else:
			tmp = max(c, tmp)
			c = 0
	count[x] = max(tmp, c)
	print(max(count))


values = []

def get_max(row):
	total = 0
	max_vv = 0
	for x in row:
		if x == 1:
			max_vv += 1
		else:
			if max_vv > total:
				total = max_vv
			max_vv = 0
	if max_vv > total:
		total = max_vv
	return total
(n, m, q) = map(int, input().split())
rows = []
for i in range(n):
	rows.append(list(map(int, input().split())))
	values.append(get_max(rows[-1]))
for i in range(q):
	(i, j) = map(int, input().split())
	i -= 1
	j -= 1
	rows[i][j] = 1 - rows[i][j]
	values[i] = get_max(rows[i])
	print(max(values))


(n, m, q) = map(int, input().split())
l = []
for i in range(n):
	l.append(list(map(int, input().split())))
count = []
for i in range(n):
	c = 0
	k = 0
	for j in range(m):
		if l[i][j] == 1:
			c += 1
		else:
			k = max(c, k)
			c = 0
	k = max(c, k)
	count.append(k)
for i in range(q):
	(a, b) = map(int, input().split())
	(a, b) = (a - 1, b - 1)
	if l[a][b] == 0:
		l[a][b] = 1
		c = 0
		k = 0
		for j in l[a]:
			if j == 1:
				c += 1
			else:
				k = max(c, k)
				c = 0
		k = max(c, k)
		count[a] = k
	else:
		l[a][b] = 0
		k = 0
		c = 0
		for j in l[a]:
			if j == 1:
				c += 1
			else:
				k = max(c, k)
				c = 0
		k = max(c, k)
		count[a] = k
	print(max(count))


(n, m, q) = [int(token) for token in input().split()]
g = []
for _ in range(n):
	row = [int(token) for token in input().split()]
	g.append(row)

def row_score(row):
	max_count = 0
	count = 0
	for item in row:
		if item == 1:
			count += 1
		else:
			count = 0
		max_count = max(max_count, count)
	return max_count
row_cache = [row_score(row) for row in g]

def score():
	return max((rc for rc in row_cache))
for turn in range(q):
	(i, j) = [int(token) - 1 for token in input().split()]
	g[i][j] = 1 - g[i][j]
	row_cache[i] = row_score(g[i])
	print(score())


(n, m, q) = map(int, input().split())
arr = []
scores = []

def get_score(line):
	cur_score = 0
	max_score = 0
	for e in line:
		if e == 1:
			cur_score += 1
		else:
			max_score = max(max_score, cur_score)
			cur_score = 0
	max_score = max(max_score, cur_score)
	return max_score
for _ in range(n):
	si = list(map(int, input().split()))
	arr.append(si)
	scores.append(get_score(si))
for _ in range(q):
	(i, j) = map(int, input().split())
	arr[i - 1][j - 1] = int(not arr[i - 1][j - 1])
	scores[i - 1] = get_score(arr[i - 1])
	max_score = max(scores)
	print(max_score)


(n, m, q) = list(map(int, input().rstrip().split()))
mat = []

def score(x):
	i = 0
	l = 0
	maxm = 0
	while i < m:
		if x[i] == 1:
			l += 1
			maxm = max(l, maxm)
		else:
			l = 0
		i += 1
	return maxm
for i in range(n):
	mat += [list(map(int, input().rstrip().split()))]
l = []
for x in mat:
	l += [score(x)]
for i in range(q):
	(x, y) = list(map(int, input().rstrip().split()))
	if mat[x - 1][y - 1] == 1:
		mat[x - 1][y - 1] = 0
	else:
		mat[x - 1][y - 1] = 1
	l[x - 1] = score(mat[x - 1])
	print(max(l))


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
from collections import Counter
import heapq
from collections import Counter

def get(x):
	curr = 0
	a = 0
	for i in x:
		if i == 1:
			curr += 1
		else:
			curr = 0
		a = max(a, curr)
	return a
(n, m, q) = map(int, input().split())
g = [[int(x) for x in input().split() + [0]] for i in range(n)]
ans = [get(i) for i in g]
for i in range(q):
	(u, v) = map(int, input().split())
	g[u - 1][v - 1] = (g[u - 1][v - 1] + 1) % 2
	ans[u - 1] = get(g[u - 1])
	print(max(ans))


def consecutive(a):
	c = 0
	m = 0
	for i in a:
		if i == 0:
			if c > m:
				m = c
			c = 0
		else:
			c += 1
	if c > m:
		m = c
	return m

def one_case():
	(n, m, q) = map(int, input().split())
	a = []
	cons = []
	for i in range(n):
		l = [int(x) for x in input().split()]
		a.append(l)
		cons.append(consecutive(l))
	for i in range(q):
		(x, y) = map(int, input().split())
		(x, y) = (x - 1, y - 1)
		a[x][y] = 1 - a[x][y]
		cons[x] = consecutive(a[x])
		print(max(cons))
t = 1
for i in range(t):
	one_case()


MOD = 1000000007
ii = lambda : int(input())
si = lambda : input()
dgl = lambda : list(map(int, input()))
f = lambda : map(int, input().split())
il = lambda : list(map(int, input().split()))
ls = lambda : list(input())
(n, m, q) = f()
l = []
maxc = []
for _ in range(n):
	l.append(il())
	c = 0 if l[-1][0] == 0 else 1
	mx = c
	for i in range(1, m):
		if l[-1][i] == l[-1][i - 1] == 1:
			c += 1
		elif l[-1][i] == 1:
			c = 1
		else:
			c = 0
		mx = max(mx, c)
	maxc.append(mx)
for _ in range(q):
	(r, c) = f()
	l[r - 1][c - 1] ^= 1
	c = 0 if l[r - 1][0] == 0 else 1
	mx = c
	for i in range(1, m):
		if l[r - 1][i] == l[r - 1][i - 1] == 1:
			c += 1
		elif l[r - 1][i] == 1:
			c = 1
		else:
			c = 0
		mx = max(mx, c)
	maxc[r - 1] = mx
	print(max(maxc))


def calc(li, m):
	ans = 0
	count = 0
	for i in range(m):
		if li[i] == 1:
			count += 1
		else:
			count = 0
		ans = max(ans, count)
	return ans
(n, m, q) = map(int, input().split())
adj = []
for i in range(n):
	li = list(map(int, input().split()))
	adj.append(li)
row = [0] * n
for i in range(n):
	row[i] = calc(adj[i], m)
for _ in range(q):
	(r, c) = map(int, input().split())
	r -= 1
	c -= 1
	adj[r][c] = 1 - adj[r][c]
	row[r] = calc(adj[r], m)
	ans = max(row)
	print(ans)


import os
import sys
import math
from io import BytesIO, IOBase
from fractions import Fraction
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
(n, m, q) = map(int, input().split())
a = [[0 for i in range(m)] for j in range(n)]
row = [0] * n
m1 = 0
for i in range(n):
	b = list(map(int, input().split()))
	curr = 0
	mx = 0
	for j in range(m):
		a[i][j] = b[j]
		if a[i][j] == 1:
			curr += 1
		else:
			mx = max(mx, curr)
			curr = 0
	mx = max(mx, curr)
	row[i] = mx
for k in range(q):
	(x, y) = map(int, input().split())
	x -= 1
	y -= 1
	a[x][y] = 1 - a[x][y]
	temp = row[x]
	curr = 0
	mx = 0
	for j in range(m):
		if a[x][j] == 1:
			curr += 1
		else:
			mx = max(mx, curr)
			curr = 0
	mx = max(mx, curr)
	row[x] = mx
	m1 = max(row)
	print(m1)


def counts(l):
	k = [0]
	e = 0
	for i in range(len(l)):
		if l[i] == 1:
			e += 1
		else:
			k.append(e)
			e = 0
	k.append(e)
	return max(k)
(n, m, q) = map(int, input().split())
l = []
for i in range(n):
	k = list(map(int, input().split()))
	l.append(k)
e = []
for i in range(n):
	e.append(counts(l[i]))
for i in range(q):
	(a, b) = map(int, input().split())
	if l[a - 1][b - 1] == 1:
		l[a - 1][b - 1] = 0
		e[a - 1] = counts(l[a - 1])
	else:
		l[a - 1][b - 1] = 1
		e[a - 1] = counts(l[a - 1])
	print(max(e))


import sys
input = sys.stdin.readline

def multi_input():
	return map(int, input().split())

def array_print(arr):
	print(' '.join(map(str, arr)))

def findsum(arr):
	ans = 0
	max1 = 0
	for i in arr:
		if i == 1:
			ans += 1
			max1 = max(ans, max1)
		else:
			max1 = max(ans, max1)
			ans = 0
	return max1
(n, m, q) = multi_input()
matrix = []
arr = [0] * n
for i in range(n):
	temp = list(multi_input())
	matrix.append(temp)
	arr[i] = findsum(temp)
for i in range(q):
	(x1, y1) = multi_input()
	x1 -= 1
	y1 -= 1
	if matrix[x1][y1] == 0:
		matrix[x1][y1] = 1
		arr[x1] = findsum(matrix[x1])
	elif matrix[x1][y1] == 1:
		matrix[x1][y1] = 0
		arr[x1] = findsum(matrix[x1])
	print(max(arr))


(n, m, p) = map(int, input().split())
ans = [0] * n
grid = []
c = r = d = 0
for i in range(n):
	li = list(map(int, input().split()))
	li = [0] + li + [0]
	grid.append(li)
	for k in range(1, m + 1):
		if li[k] == 1:
			r = 1
			if li[k - 1] == 1:
				c += 1
		else:
			d = max(c + r, d)
			c = 0
	d = max(d, c + r)
	ans[i] = d
	c = d = 0
for i in range(p):
	(a, b) = map(int, input().split())
	c = r = d = 0
	if grid[a - 1][b] == 0:
		grid[a - 1][b] = 1
	else:
		grid[a - 1][b] = 0
	for k in range(1, m + 1):
		if grid[a - 1][k] == 1:
			r = 1
			if grid[a - 1][k - 1] == 1:
				c += 1
		else:
			d = max(d, c + r)
			c = 0
	d = max(c + r, d)
	ans[a - 1] = d
	c = d = 0
	print(max(ans))


(n, m, q) = map(int, input().split())
g = [list(map(int, input().split())) for i in range(n)]
l = [0] * n
for i in range(n):
	res = 0
	cnt = 0
	for j in range(m):
		if g[i][j] == 1:
			cnt += 1
		else:
			res = max(res, cnt)
			cnt = 0
	res = max(res, cnt)
	l[i] = res
for _ in range(q):
	(y, x) = map(int, input().split())
	y -= 1
	x -= 1
	g[y][x] = 1 - g[y][x]
	cnt = 0
	ans = 0
	for i in range(m):
		if g[y][i] == 1:
			cnt += 1
		else:
			ans = max(ans, cnt)
			cnt = 0
	ans = max(ans, cnt)
	l[y] = ans
	print(max(l))


(n, m, q) = input().split()
n = int(n)
m = int(m)
q = int(q)
a = []
for i in range(n):
	b = input().split()
	for j in range(m):
		b[j] = int(b[j])
	a.append(b)

def func(i):
	ans = 0
	l = -1
	for j in range(m):
		if a[i][j] == 0:
			l = j
		else:
			ans = max(ans, j - l)
	return ans
c = list(map(func, range(n)))
for i in range(q):
	(z, x) = map(int, input().split())
	z -= 1
	x -= 1
	a[z][x] = 1 - a[z][x]
	c[z] = func(z)
	print(max(c))


import math as mt
import sys, string
input = sys.stdin.readline
import random
from collections import deque, defaultdict
L = lambda : list(map(int, input().split()))
Ls = lambda : list(input().split())
M = lambda : map(int, input().split())
I = lambda : int(input())

def msub(a):
	c = 0
	g = 0
	for i in range(len(a)):
		if a[i] == 1:
			c += 1
			g = max(g, c)
		elif a[i] == 0:
			g = max(g, c)
			c = 0
	return g
(n, m, q) = M()
ans = [0] * n
l = []
for i in range(n):
	a = L()
	l.append(a)
	ans[i] = msub(a)
for i in range(q):
	(r, c) = M()
	r -= 1
	c -= 1
	l[r][c] ^= 1
	ans[r] = msub(l[r])
	print(max(ans))


a = lambda : input().split()
d = lambda s: max(map(len, ''.join(s).split('0')))
(n, m, q) = map(int, a())
matr = [a() for _ in range(n)]
item = [*map(d, matr)]
for _ in range(q):
	(i, j) = map(int, a())
	matr[i - 1][j - 1] = str(1 - int(matr[i - 1][j - 1]))
	item[i - 1] = d(matr[i - 1])
	print(max(item))


(n, m, q) = map(int, input().split())
s = []
t = []

def getMax(line):
	cur = 0
	res = 0
	for v in line:
		if v == 1:
			cur += 1
		else:
			res = max(res, cur)
			cur = 0
	res = max(res, cur)
	return res
for i in range(n):
	si = list(map(int, input().split()))
	s.append(si)
	t.append(getMax(si))
for qi in range(q):
	(i, j) = map(int, input().split())
	s[i - 1][j - 1] = int(not s[i - 1][j - 1])
	t[i - 1] = getMax(s[i - 1])
	res = max(t)
	print(res)


def get_row_score(row):
	max_score = 0
	current_score = int(row[0])
	last = row[0]
	for e in row[1:]:
		if e:
			if current_score == 0:
				current_score = 1
			if e == last:
				current_score += 1
		else:
			max_score = max(max_score, current_score)
			current_score = 0
		last = e
	return max(max_score, current_score)
(n, m, q) = map(int, input().split())
grid = []
row_scores = [0] * n
for i in range(n):
	row = list(map(bool, map(int, input().split())))
	row_scores[i] = get_row_score(row)
	grid.append(row)
for _ in range(q):
	(i, j) = map(int, input().split())
	i -= 1
	j -= 1
	grid[i][j] = not grid[i][j]
	row_scores[i] = get_row_score(grid[i])
	print(max(row_scores))


def f(s):
	s = ''.join(s).split('0')
	return max((len(i) for i in s))
(n, m, q) = map(int, input().split())
arr = [input().split() for i in range(n)]
b = [f(s) for s in arr]
for i in range(q):
	(x, y) = map(int, input().split())
	x -= 1
	y -= 1
	arr[x][y] = str(1 - int(arr[x][y]))
	b[x] = f(arr[x])
	print(max(b))


(n, m, q) = map(int, input().split())
s = [input().split() for i in range(n)]
f = lambda i: max(map(len, ''.join(s[i]).split('0')))
a = list(map(f, range(n)))
for i in range(q):
	(x, y) = map(int, input().split())
	x -= 1
	y -= 1
	s[x][y] = '1' if s[x][y] == '0' else '0'
	a[x] = f(x)
	print(max(a))


(n, m, q) = map(int, input().split())
bears = [list(map(int, input().split())) for i in range(n)]
maxns = [0] * n
for i in range(n):
	num = bears[i][0]
	maxns[i] = num
	for j in range(1, m):
		num = num * (bears[i][j] == bears[i][j - 1]) + bears[i][j]
		maxns[i] = max(maxns[i], num)
for i in range(q):
	(i, j) = map(int, input().split())
	i -= 1
	j -= 1
	bears[i][j] ^= 1
	num = bears[i][0]
	maxns[i] = num
	for j in range(1, m):
		num = num * (bears[i][j] == bears[i][j - 1]) + bears[i][j]
		maxns[i] = max(maxns[i], num)
	print(max(maxns))


(n, m, k) = [int(x) for x in input().split()]
a = []
b = []
for i in range(n):
	a.append([int(x) for x in input().split()])
	b.append(0)
	cur = 0
	for j in range(m):
		if a[i][j] == 0:
			cur = 0
		else:
			cur += 1
		b[i] = max(b[i], cur)
for i in range(k):
	(x, y) = [int(x) - 1 for x in input().split()]
	if a[x][y] == 1:
		a[x][y] = 0
	else:
		a[x][y] = 1
	cur = 0
	b[x] = 0
	for j in range(m):
		if a[x][j] == 0:
			cur = 0
		else:
			cur += 1
		b[x] = max(b[x], cur)
	res = 0
	for i in b:
		res = max(res, i)
	print(res)


from sys import stdin
input = stdin.readline

def get(l):
	res = 0
	cur = 0
	for x in l:
		cur = (cur + x) * x
		res = max(res, cur)
	return res
(n, m, q) = (int(x) for x in input().split())
f = [[int(x) for x in input().split()] + [0] for i in range(n)]
reses = [get(r) for r in f]
for i in range(q):
	(i, j) = (int(x) - 1 for x in input().split())
	f[i][j] ^= 1
	reses[i] = get(f[i])
	print(max(reses))


def calscore(a, r, m):
	s = 0
	l = 0
	if [0] * m == a[r]:
		return l
	for i in range(len(a[r]) - 1):
		if a[r][i] == 1 and a[r][i + 1] == 1:
			s += 1
		else:
			s += 1
			l = max(l, s)
			s = 0
	try:
		if a[r][-1] == 1 and a[r][-2] == 1:
			s += 1
		l = max(s, l)
	except:
		if a[r][-1] == 1:
			s += 1
		l = max(s, l)
	return l
(n, m, q) = map(int, input().split())
a = []
for i in range(n):
	c = list(map(int, input().split()))
	a.append(c)
scores = []
for i in range(len(a)):
	scores.append(calscore(a, i, m))
p = max(scores)
for i in range(q):
	(x, y) = map(int, input().split())
	a[x - 1][y - 1] = int(not a[x - 1][y - 1])
	scores[x - 1] = calscore(a, x - 1, m)
	print(max(scores))


def get_info_current(grid, x, y, m):
	dist_r = 0
	hit = False
	if x % m != m - 1:
		for i in range(x + 1, m):
			if grid[i + y * m] != 1:
				dist_r = i - x - 1
				hit = True
				break
		if not hit:
			dist_r = m - x - 1
	dist_l = 0
	hit = False
	if x % m != 0:
		for i in range(x - 1, -1, -1):
			if grid[i + y * m] != 1:
				dist_l = x - i - 1
				hit = True
				break
		if not hit:
			dist_l = x - -1 - 1
	return (dist_r, dist_l)

def do_simulation(grid, n, m):
	max_val = 0
	current_run = 0
	for i in range(0, n * m):
		if i % m == 0:
			if current_run > max_val:
				max_val = current_run
			current_run = 0
		if grid[i] == 1:
			current_run += 1
		else:
			if current_run > max_val:
				max_val = current_run
			current_run = 0
	if current_run > max_val:
		max_val = current_run
	return max_val

def main():
	invalues = input().strip().split(' ')
	(n, m, q) = (int(invalues[0]), int(invalues[1]), int(invalues[2]))
	grid = [0 for _ in range(0, n * m)]
	for i in range(0, n):
		row = input().strip().split(' ')
		for x in range(0, m):
			grid[i * m + x] = int(row[x])
	max_val = do_simulation(grid, n, m)
	for round in range(0, q):
		invalues = input().strip().split(' ')
		(x, y) = (int(invalues[1]) - 1, int(invalues[0]) - 1)
		(dist_r, dist_l) = get_info_current(grid, x, y, m)
		val = grid[x + y * m]
		if val == 1:
			grid[x + y * m] = 0
			if dist_r + dist_l + 1 == max_val:
				max_val = do_simulation(grid, n, m)
		else:
			grid[x + y * m] = 1
			if dist_r + dist_l + 1 > max_val:
				max_val = dist_r + dist_l + 1
		print('{}'.format(max_val))
main()


class CodeforcesTask548BSolution:

	def __init__(self):
		self.result = ''
		self.n_m_q = []
		self.grid = []
		self.actions = []

	def read_input(self):
		self.n_m_q = [int(x) for x in input().split(' ')]
		for _ in range(self.n_m_q[0]):
			self.grid.append([int(y) for y in input().split(' ')])
		for _ in range(self.n_m_q[2]):
			self.actions.append([int(y) for y in input().split(' ')])

	def process_task(self):
		maxes = [0] * self.n_m_q[0]
		for row in range(self.n_m_q[0]):
			mx = 0
			cr = 0
			for y in range(self.n_m_q[1]):
				if self.grid[row][y]:
					cr += 1
					mx = max(mx, cr)
				else:
					cr = 0
			maxes[row] = mx
		res = []
		for action in self.actions:
			self.grid[action[0] - 1][action[1] - 1] = 0 if self.grid[action[0] - 1][action[1] - 1] else 1
			mx = 0
			cr = 0
			for y in range(self.n_m_q[1]):
				if self.grid[action[0] - 1][y]:
					cr += 1
					mx = max(mx, cr)
				else:
					cr = 0
			maxes[action[0] - 1] = mx
			res.append(str(max(maxes)))
		self.result = '\n'.join(res)

	def get_result(self):
		return self.result
Solution = CodeforcesTask548BSolution()
Solution.read_input()
Solution.process_task()
print(Solution.get_result())


(n, m, q) = [int(i) for i in input().split()]
matrix = []
for i in range(n):
	matrix.append([int(i) for i in input().split()])
maxprrow = []
for a in range(n):
	maxrow = 0
	max_max = 0
	for b in range(m):
		if matrix[a][b] == 1:
			maxrow += 1
			if maxrow > max_max:
				max_max = maxrow
		else:
			maxrow = 0
	maxprrow.append(max_max)
winer = []
for step in range(q):
	(i, j) = [int(c) for c in input().split()]
	matrix[i - 1][j - 1] = 1 - matrix[i - 1][j - 1]
	(max_max, maxrow) = (0, 0)
	for b in range(m):
		if matrix[i - 1][b] == 1:
			maxrow += 1
			if maxrow > max_max:
				max_max = maxrow
		else:
			maxrow = 0
	maxprrow[i - 1] = max_max
	winer.append(max(maxprrow))
for w in winer:
	print(w)


def kadane(lst):
	ans = s = 0
	for n in lst:
		if n == 0:
			ans = max(ans, s)
			s = 0
		else:
			s += 1
	return max(ans, s)
(n, m, q) = map(int, input().split())
f = []
best = []
for _ in range(n):
	l = list(map(int, input().split()))
	f.append(l)
	best.append(kadane(l))
for _ in range(q):
	(i, j) = map(int, input().split())
	f[i - 1][j - 1] = (f[i - 1][j - 1] + 1) % 2
	best[i - 1] = kadane(f[i - 1])
	print(max(best))


def read_data():
	(n, m, q) = map(int, input().split())
	grid = []
	for i in range(n):
		grid.append(list(map(int, input().split())))
	qs = []
	for i in range(q):
		(x, y) = map(int, input().split())
		qs.append((x - 1, y - 1))
	return (n, m, q, grid, qs)

def max_cons(row):
	mc = 0
	tmp = 0
	for v in row:
		if v:
			tmp += 1
		else:
			if tmp > mc:
				mc = tmp
			tmp = 0
	return max(mc, tmp)

def solve(n, m, q, grid, qs):
	mcc = [max_cons(row) for row in grid]
	for (x, y) in qs:
		row = grid[x]
		row[y] = 1 - row[y]
		mcc[x] = max_cons(row)
		print(max(mcc))
param = read_data()
solve(*param)


def main():
	(n, m, q) = map(int, input().split())
	l = [[c == '1' for c in input()[::2]] for _ in range(n)]

	def f(ro):
		res = z = 0
		for t in ro:
			if t:
				z += 1
			else:
				if res < z:
					res = z
				z = 0
		if res < z:
			res = z
		return res
	f_rows = list(map(f, l))
	cnt = [0] * (m + 1)
	for r in f_rows:
		cnt[r] += 1
	m = str(max(f_rows))
	res = []
	for _ in range(q):
		(y, x) = map(int, input().split())
		x -= 1
		y -= 1
		(row, s0) = (l[y], f_rows[y])
		row[x] ^= True
		s1 = f(row)
		if s1 != s0:
			f_rows[y] = s1
			m = str(max(f_rows))
		res.append(m)
	print('\n'.join(res))
main()


__author__ = 'Andrey'

def retest(row):
	nonlocal table
	row_n = table[row]
	m_ax = 0
	curr = 0
	for item in row_n:
		if item == 1:
			curr += 1
		if item == 0:
			m_ax = max(curr, m_ax)
			curr = 0
	m_ax = max(curr, m_ax)
	return m_ax
(n, m, q) = list(map(int, input().split()))
table = []
for x in range(n):
	table.append(list(map(int, input().split())))
maximums = []
for y in range(n):
	maximums.append(retest(y))
for z in range(q):
	(i, j) = list(map(int, input().split()))
	table[i - 1][j - 1] = 1 - table[i - 1][j - 1]
	maximums[i - 1] = retest(i - 1)
	print(max(maximums))


def getOnes(li):
	ans = 0
	ret = 0
	for i in li:
		if i == 0:
			ans = 0
		else:
			ans += 1
		ret = max(ans, ret)
	return ret
(rows, cols, rounds) = map(int, input().split())
mat = []
scores = []
for i in range(rows):
	mat.append(list(map(int, input().split())))
	scores.append(getOnes(mat[i]))
for i in range(rounds):
	(k, b) = map(int, input().split())
	k -= 1
	b -= 1
	if mat[k][b] == 0:
		mat[k][b] = 1
	else:
		mat[k][b] = 0
	maxi = 0
	scores[k] = getOnes(mat[k])
	maxi = max(scores)
	print(maxi)


def fff(i):
	nonlocal a
	nonlocal m
	t = 0
	max = 0
	for j in range(m + 1):
		if a[i][j] == 0:
			if t > max:
				max = t
			t = 0
		else:
			t = t + 1
	return max
(n, m, q) = list(map(int, input().split()))
a = []
s = []
for i in range(0, n):
	w = list(map(int, input().split()))
	w.append(0)
	a.append(w)
	s.append(fff(i))
for i in range(q):
	(x, y) = list(map(int, input().split()))
	a[x - 1][y - 1] = (a[x - 1][y - 1] + 1) % 2
	s[x - 1] = fff(x - 1)
	print(max(s))


def read_input():
	return input().split()

def score_rows(row):
	return max(map(len, ''.join(map(str, row)).split('0')))
(rows, cols, num_turns) = map(int, read_input())
grid = [[int(i) for i in read_input()] for _ in range(rows)]
scores = list(map(score_rows, grid))
for turn in range(num_turns):
	(row, col) = map(int, read_input())
	grid[row - 1][col - 1] = int(not grid[row - 1][col - 1])
	scores[row - 1] = score_rows(grid[row - 1])
	print(max(scores))


def score(R):
	val = 0
	ret = 0
	for i in R:
		if i:
			val += 1
			ret = max(ret, val)
		else:
			val = 0
	return ret
(n, m, q) = map(int, input().split())
A = [list(map(int, input().split())) for i in range(n)]
B = [score(A[i]) for i in range(n)]
for _ in range(q):
	(x, y) = map(int, input().split())
	(x, y) = (x - 1, y - 1)
	A[x][y] = not A[x][y]
	B[x] = score(A[x])
	print(max(B))


(n, m, q) = map(int, input().split())
g = [[0] * m for i in range(0, n)]
cnt = [0] * n
for i in range(0, n):
	g[i] = list(map(int, input().split()))
for i in range(0, n):
	c = 0
	for j in range(0, m):
		if g[i][j] == 0:
			if c > cnt[i]:
				cnt[i] = c
			c = -1
		c += 1
	if c > cnt[i]:
		cnt[i] = c
for i in range(0, q):
	(r, c) = map(int, input().split())
	r -= 1
	c -= 1
	g[r][c] = not g[r][c]
	cnt[r] = 0
	c = 0
	for j in range(0, m):
		if g[r][j] == 0:
			if c > cnt[r]:
				cnt[r] = c
			c = -1
		c += 1
	if c > cnt[r]:
		cnt[r] = c
	print(max(cnt))


(n, m, q) = list(map(int, input().split()))
grid = []
for _ in range(n):
	row = list(map(int, input().split()))
	grid.append(row)

def consecutive_one(row_number):
	ans = 0
	c = 0
	for j in range(m):
		if grid[row_number][j] == 0:
			c = 0
		else:
			c += 1
		ans = max(ans, c)
	return ans
values = []
for i in range(n):
	values.append(consecutive_one(i))
for _ in range(q):
	(i, j) = list(map(int, input().split()))
	if grid[i - 1][j - 1]:
		grid[i - 1][j - 1] = 0
	else:
		grid[i - 1][j - 1] = 1
	values[i - 1] = consecutive_one(i - 1)
	print(max(values))


import sys

def read(line):
	return [int(c) for c in line.strip().split()]

def count_row(grid, i, m):
	cnt = 0 if grid[i][0] == 0 else 1
	res = 0
	for j in range(1, m):
		(cur, prev) = (grid[i][j], grid[i][j - 1])
		if cur == 1 and prev == 1:
			cnt += 1
		elif cur == 0 and prev == 1:
			res = max(res, cnt)
			cnt = 0
		elif cur == 1 and prev == 0:
			cnt = 1
	res = max(res, cnt)
	return res

def main():
	test = sys.stdin.readlines()
	(n, m, q) = read(test[0])
	grid = []
	for i in range(1, n + 1):
		grid.append(read(test[i]))
	queries = [read(line) for line in test[n + 1:]]
	scores = [0] * n
	for i in range(n):
		scores[i] = count_row(grid, i, m)
	for (x, y) in queries:
		grid[x - 1][y - 1] = 1 if grid[x - 1][y - 1] == 0 else 0
		scores[x - 1] = count_row(grid, x - 1, m)
		print(max(scores))
main()


def su(grid):
	(ans, l) = (0, 0)
	for v in grid:
		if v == 1:
			l += 1
		else:
			l = 0
		ans = max(l, ans)
	return ans
(n, m, q) = map(int, input().split(' '))
grid = []
for i in range(n):
	grid.append(list(map(int, input().split())))
s = list(map(su, grid))
for _ in range(q):
	(i, j) = map(int, input().split(' '))
	(i, j) = (i - 1, j - 1)
	if grid[i][j] == 0:
		s[i] += 1
	else:
		s[i] -= 1
	grid[i][j] = 1 - grid[i][j]
	s[i] = su(grid[i])
	print(max(s))


from io import StringIO
import sys
data = sys.stdin

def score_line(row):
	score = 0
	max_score = 0
	combo = False
	for b in row:
		if b == 1:
			if combo:
				score += 1
			else:
				score = 1
				combo = True
		else:
			score = 0
			combo = False
		max_score = max(score, max_score)
	return max_score
rows = []
(n, m, q) = map(int, data.readline().split(' '))
for i in range(n):
	rows.append(list(map(int, data.readline().split(' '))))
row_scores = list(map(score_line, rows))
for i in range(q):
	(r, c) = map(int, data.readline().split(' '))
	rows[r - 1][c - 1] = 1 - rows[r - 1][c - 1]
	row_scores[r - 1] = score_line(rows[r - 1])
	print(max(row_scores))


import math

def linescore(line):
	acc = 0
	ret = 0
	for eye in line:
		if eye:
			acc += 1
			ret = max(ret, acc)
		else:
			acc = 0
	return ret

def main():
	items = input().split()
	n = int(items[0])
	m = int(items[1])
	q = int(items[2])
	e = [[None for _ in range(m)] for _ in range(n)]
	ls = [0 for _ in range(n)]
	for i in range(n):
		items = input().split()
		for j in range(m):
			e[i][j] = items[j] == '1'
	for i in range(n):
		ls[i] = linescore(e[i])
	for qi in range(q):
		items = input().split()
		x = int(items[0]) - 1
		y = int(items[1]) - 1
		e[x][y] = not e[x][y]
		ls[x] = linescore(e[x])
		print(max(ls))

def __starting_point():
	main()
__starting_point()


import sys
input = sys.stdin.readline

def abhi():
	roe = [0] * n
	for j in range(n):
		ans = 0
		if m == 1:
			ans = max(ans, t[j][0])
		else:
			temp = t[j][0]
			for k in range(1, m):
				if t[j][k - 1] == 1 and t[j][k] == 1:
					temp += 1
				else:
					ans = max(temp, ans)
					temp = t[j][k]
			ans = max(temp, ans)
		roe[j] = ans
	return roe
(n, m, q) = map(int, input().split())
t = []
for j in range(n):
	t.append(list(map(int, input().split())))
row = abhi()
for j in range(q):
	(a, b) = map(int, input().split())
	a -= 1
	b -= 1
	t[a][b] = abs(1 - t[a][b])
	ans1 = 0
	mx = 0
	for j in range(m):
		if j == 0:
			ans1 = t[a][j]
		elif t[a][j] == 1:
			ans1 += 1
		else:
			mx = max(mx, ans1)
			ans1 = t[a][j]
	mx = max(ans1, mx)
	row[a] = mx
	print(max(row))


(n, m, q) = map(int, input().split())
arr = []
ans = [0] * n
for j in range(n):
	s = list(map(int, input().split()))
	maxx = 0
	cnt = 1
	if len(s) == 1:
		ans[j] = s[0]
	else:
		for i in range(m):
			if i < m - 1 and s[i] == s[i + 1] and (s[i] == 1):
				cnt += 1
			else:
				maxx = max(cnt, maxx)
				cnt = 1
		ans[j] = maxx
	arr.append(s)
for j in range(q):
	(a, b) = map(int, input().split())
	a -= 1
	b -= 1
	arr[a][b] = arr[a][b] ^ 1
	s = arr[a]
	if len(s) == 1:
		ans[a] = s[0]
	else:
		maxx = 0
		cnt = 1
		for i in range(m):
			if i < m - 1 and s[i] == s[i + 1] and (s[i] == 1):
				cnt += 1
			else:
				maxx = max(cnt, maxx)
				cnt = 1
		ans[a] = maxx
	print(max(ans))


def func(lst):
	summ = 0
	maxi = 0
	for i in range(m):
		if lst[i] == 0:
			summ = 0
		else:
			summ += 1
		if maxi < summ:
			maxi = summ
	return maxi
(n, m, q) = map(int, input().split())
arr = []
for i in range(n):
	lst = list(map(int, input().split()))
	sm = func(lst)
	lst.append(sm)
	arr.append(lst)
for i in range(q):
	maxim = 0
	(x, y) = map(int, input().split())
	(x, y) = (x - 1, y - 1)
	arr[x][y] = (arr[x][y] + 1) % 2
	del arr[x][-1]
	sm = func(arr[x])
	arr[x].append(sm)
	for j in range(n):
		if arr[j][-1] > maxim:
			maxim = arr[j][-1]
	print(maxim)


(n, m, q) = map(int, input().split())
grid = [[[None] * m] for _ in range(n)]
row_count = [0] * n
for i in range(n):
	grid[i] = [int(x) for x in input().split()]
max_row = None
max_counter = 0
for i in range(n):
	counter = 0
	for j in range(m):
		counter = counter + 1 if grid[i][j] else 0
		row_count[i] = max(row_count[i], counter)
		if counter > max_counter:
			max_counter = counter
			max_row = i
for _ in range(q):
	(i, j) = map(int, input().split())
	i -= 1
	j -= 1
	grid[i][j] = 0 if grid[i][j] == 1 else 1
	if grid[i][j] == 1:
		row_count[i] += 1
	else:
		row_count[i] -= 1
	counter = 0
	row_count[i] = 0
	for k in range(m):
		counter = counter + 1 if grid[i][k] else 0
		row_count[i] = max(row_count[i], counter)
	if row_count[i] > max_counter:
		max_counter = counter
		max_row = i
	print(max(row_count))


def solve(i):
	best = 0
	l = -1
	for j in range(m):
		if mat[i][j] == 0:
			l = j
		else:
			best = max(best, j - l)
	return best
(n, m, q) = map(int, input().split())
mat = [[int(j) for j in input().split()] for i in range(n)]
rows = list(map(solve, range(n)))
while q:
	(i, j) = map(int, input().split())
	i -= 1
	j -= 1
	mat[i][j] = 1 - mat[i][j]
	rows[i] = solve(i)
	print(max(rows))
	q -= 1


def arr_inp():
	return [int(x) for x in stdin.readline().split()]

def change(x):
	(c, mem[x]) = (0, 0)
	for j in grid[x]:
		if j:
			c += 1
		else:
			mem[x] = max(mem[x], c)
			c = 0
	mem[x] = max(mem[x], c)
	return mem[x]
from sys import stdin
from collections import defaultdict
(n, m, q) = arr_inp()
grid = [arr_inp() for i in range(n)]
mem = defaultdict(int)
for i in range(n):
	mem[i] = change(i)
for i in range(q):
	(r, c) = arr_inp()
	r -= 1
	c -= 1
	if grid[r][c]:
		grid[r][c] = 0
	else:
		grid[r][c] = 1
	mem[r] = change(r)
	print(max(mem.values()))


import sys
import collections
import random
import time
import itertools
input = sys.stdin.readline
(N, M, Q) = map(int, input().strip().split())
A = [list(map(int, input().strip().split())) for _ in range(N)]

def consecutive_one(idx):
	mx = 0
	for (k, grp) in itertools.groupby(A[idx]):
		mx = max(mx, len(list(grp))) if k == 1 else mx
	return mx
max_A = [consecutive_one(i) for i in range(N)]
for query in range(Q):
	(i, j) = map(int, input().strip().split())
	i -= 1
	j -= 1
	A[i][j] = 1 if A[i][j] == 0 else 0
	max_A[i] = consecutive_one(i)
	print(max(max_A))


def cal(l):
	t = 0
	r = 0
	for i in range(len(l)):
		if l[i] == '1':
			t += 1
			r = max(r, t)
		else:
			t = 0
	return r

def maxll(l):
	r = 0
	for i in l:
		r = max(r, i)
	return r
inp = input().split()
n = int(inp[0])
m = int(inp[1])
q = int(inp[2])
count = [0 for i in range(n)]
a = [['' for i in range(m)] for j in range(n)]
for i in range(n):
	s = input().split()
	a[i] = s
	count[i] = cal(a[i])
for i in range(q):
	s = input().split()
	x = int(s[0])
	y = int(s[1])
	if a[x - 1][y - 1] == '1':
		a[x - 1][y - 1] = '0'
	else:
		a[x - 1][y - 1] = '1'
	count[x - 1] = cal(a[x - 1])
	print(maxll(count))


import sys
(N, M, Q) = input().split()
N = int(N)
M = int(M)
Q = int(Q)
rows = []
score_of_row = []

def score(row):
	score_so_far = 0
	max_score = float('-inf')
	for r in row:
		if r == 0:
			score_so_far = 0
		else:
			score_so_far += 1
		max_score = max(max_score, score_so_far)
	return max_score
for _ in range(N):
	row = [int(x) for x in input().split()]
	rows += [row]
	score_of_row += [score(row)]
for _ in range(Q):
	(r, c) = input().split()
	(r, c) = (int(r), int(c))
	rows[r - 1][c - 1] = 1 - rows[r - 1][c - 1]
	score_of_row[r - 1] = score(rows[r - 1])
	print(max(score_of_row))


(n, m, q) = list(map(int, input().split()))
grid = [list(map(int, input().split())) for i in range(n)]

def findMax(i):
	ans = 0
	l = -1
	for j in range(m):
		if grid[i][j] == 0:
			l = j
		else:
			ans = max(ans, j - l)
	return ans
V = list(map(findMax, range(n)))
for i in range(q):
	(row, col) = map(int, input().split())
	row -= 1
	col -= 1
	grid[row][col] = 1 - grid[row][col]
	V[row] = findMax(row)
	print(max(V))


a = list()
b = list()
(n, m, q) = [int(s) for s in input().split()]
for i in range(n):
	a.append([s for s in input().split()])
	b.append(max([len(s) for s in ''.join(a[i]).split('0')]))
for i in range(q):
	(p, o) = [int(s) - 1 for s in input().split()]
	a[p][o] = str(1 - int(a[p][o]))
	b[p] = max([len(s) for s in ''.join(a[p]).split('0')])
	print(max(b))


import sys
inf = float('inf')
from math import ceil, floor, log, sqrt, factorial, pow, pi, gcd

def func(Array):
	result = Array[0]
	maxi = Array[0]
	for i in range(1, m):
		if Array[i] == 0:
			maxi = max(maxi, result)
			result = 0
		elif Array[i] == 1:
			result += 1
	maxi = max(result, maxi)
	return maxi

def get_array():
	return list(map(int, sys.stdin.readline().strip().split()))

def get_ints():
	return map(int, sys.stdin.readline().strip().split())

def input():
	return sys.stdin.readline().strip()
(n, m, q) = get_ints()
mat = []
for i in range(n):
	mat.append(get_array())
score = []
for i in mat:
	score.append(func(i))
for i in range(q):
	(r, c) = get_ints()
	r -= 1
	c -= 1
	mat[r][c] = mat[r][c] ^ 1
	new_score = func(mat[r])
	score[r] = new_score
	print(max(score))


def counting(a):
	l = 0
	cnt = 0
	for e in a:
		if e == 1:
			l += 1
		else:
			if l > cnt:
				cnt = l
			l = 0
	if l > cnt:
		cnt = l
	return cnt

def main():
	(n, m, q) = map(int, input().split(' '))
	cnt = [0 for i in range(n)]
	f = [[] for i in range(n)]
	maxc = 0
	for i in range(n):
		f[i] = list(map(int, input().split()))
		cnt[i] = counting(f[i])
		if cnt[i] > maxc:
			maxc = cnt[i]
	for p in range(q):
		(i, j) = map(lambda la: int(la) - 1, input().split(' '))
		f[i][j] = (int(f[i][j]) + 1) % 2
		cnt[i] = counting(f[i])
		print(max(cnt))
main()


(n, m, q) = list(map(int, input().split()))
g = []
for i in range(n):
	g.append(list(map(int, input().split())))
ct = []
for i in range(n):
	j = 0
	ma = 0
	while j < m:
		if g[i][j] == 1:
			c = 0
			while g[i][j] == 1:
				c = c + 1
				j = j + 1
				if j == m:
					break
			ma = max(ma, c)
		else:
			j = j + 1
	ct.append(ma)
for k in range(q):
	(i, j) = list(map(int, input().split()))
	(i, j) = (i - 1, j - 1)
	g[i][j] = 0 if g[i][j] == 1 else 1
	j = 0
	ma = 0
	while j < m:
		if g[i][j] == 1:
			c = 0
			while g[i][j] == 1:
				c = c + 1
				j = j + 1
				if j == m:
					break
			ma = max(ma, c)
		else:
			j = j + 1
	ct[i] = ma
	print(max(ct))


import sys

def read(line):
	return [int(c) for c in line.strip().split()]

def count_row(grid, row):
	cnt = int(grid[row][0] == 1)
	res = 0
	for j in range(1, len(grid[0])):
		(cur, prev) = (grid[row][j], grid[row][j - 1])
		if cur == 1 and prev == 1:
			cnt += 1
		elif cur == 0 and prev == 1:
			res = max(res, cnt)
			cnt = 0
		elif cur == 1 and prev == 0:
			cnt = 1
	return max(res, cnt)

def main():
	test = sys.stdin.readlines()
	(n, _m, _q) = read(test[0])
	grid = [read(test[i]) for i in range(1, n + 1)]
	scores = [count_row(grid, i) for i in range(n)]
	for (i, j) in (read(line) for line in test[n + 1:]):
		i -= 1
		j -= 1
		grid[i][j] = 1 - grid[i][j]
		scores[i] = count_row(grid, i)
		print(max(scores))
main()


(n, m, q) = [int(i) for i in input().split()]
t = []
u = []
for i in range(n):
	t.append([int(i) for i in input().split()])
	s = 0
	o = 0
	for k in t[-1]:
		if k == 1:
			s += 1
			o = max(s, o)
		else:
			s = 0
	u.append(o)
answer = []
for i in range(q):
	(a, b) = [int(i) - 1 for i in input().split()]
	if t[a][b] == 1:
		t[a][b] = 0
	else:
		t[a][b] = 1
	s = 0
	o = 0
	for k in t[a]:
		if k == 1:
			s += 1
			o = max(s, o)
		else:
			s = 0
	u[a] = o
	answer.append(max(u))
for i in answer:
	print(i)


(n, m, q) = [int(i) for i in input().split()]
matrix = []
arr = []
for i in range(n):
	matrix.append([int(i) for i in input().split()])
for i in range(n):
	cur = 0
	ans = 0
	for j in range(m):
		if matrix[i][j] == 1:
			cur += 1
		else:
			ans = max(ans, cur)
			cur = 0
	ans = max(ans, cur)
	arr.append(ans)
for i in range(q):
	(x, y) = [int(i) for i in input().split()]
	matrix[x - 1][y - 1] = (matrix[x - 1][y - 1] + 1) % 2
	cur = 0
	ans = 0
	for j in range(m):
		if matrix[x - 1][j] == 1:
			cur += 1
		else:
			ans = max(ans, cur)
			cur = 0
	ans = max(ans, cur)
	arr[x - 1] = ans
	print(max(arr))


(n, m, q) = map(int, input().split(' '))
l = []

def maxx(l):
	cmax = 0
	count = 0
	for i in range(len(l)):
		for j in range(len(l[i])):
			if l[i][j] == 1:
				count += 1
				if j == len(l[i]) - 1 and count > cmax:
					cmax = count
			else:
				if count > cmax:
					cmax = count
				count = 0
		count = 0
	return cmax

def maxi(l):
	c = 0
	cmax = 0
	for i in range(len(l)):
		if l[i] == 1:
			c += 1
			if c > cmax:
				cmax = c
		else:
			c = 0
	return cmax
for i in range(n):
	li = list(map(int, input().split(' ')))
	l.append(li)
foo = []
for i in range(len(l)):
	foo.append(maxi(l[i]))
for i in range(q):
	(i, j) = map(int, input().split(' '))
	l[i - 1][j - 1] = 1 - l[i - 1][j - 1]
	foo[i - 1] = maxi(l[i - 1])
	print(max(foo))


(n, m, q) = map(int, input().split())
mat = []
for i in range(n):
	mat.append([int(i) for i in input().split()])
maxr = [0] * n
for i in range(n):
	j = 0
	maxi = 0
	while j < m:
		if mat[i][j] == 1:
			c = 0
			while j < m and mat[i][j] == 1:
				c += 1
				j += 1
			maxi = max(maxi, c)
		else:
			j += 1
	maxr[i] = maxi
for i in range(q):
	(x, y) = map(int, input().split())
	x -= 1
	y -= 1
	mat[x][y] = 1 - mat[x][y]
	maxi = 0
	j = 0
	while j < m:
		if mat[x][j] == 1:
			c = 0
			while j < m and mat[x][j] == 1:
				c += 1
				j += 1
			maxi = max(maxi, c)
		else:
			j += 1
	maxr[x] = maxi
	print(max(maxr))


(n, m, q) = map(int, input().split())
xs = [list(map(int, input().split())) for i in range(n)]

def go(xs):
	(answer, total) = (0, 0)
	for x in xs:
		total = total + 1 if x else 0
		answer = total if total > answer else answer
	return answer
ss = [go(x) for x in xs]
for i in range(q):
	(i, j) = map(int, input().split())
	if xs[i - 1][j - 1] == 0:
		xs[i - 1][j - 1] = 1
		ss[i - 1] = go(xs[i - 1])
	else:
		xs[i - 1][j - 1] = 0
		ss[i - 1] = go(xs[i - 1])
	print(max(ss))


(n, m, q) = [int(c) for c in input().split()]
matrix = []
for i in range(n):
	matrix.append([int(c) for c in input().split()])
maxperrow = []
for a in range(n):
	maxrow = 0
	maxmax = 0
	for b in range(m):
		if matrix[a][b] == 1:
			maxrow += 1
			if maxrow > maxmax:
				maxmax = maxrow
		else:
			maxrow = 0
	maxperrow.append(maxmax)
winner = []
for step in range(q):
	(i, j) = [int(c) for c in input().split()]
	matrix[i - 1][j - 1] = 1 - matrix[i - 1][j - 1]
	maxmax = 0
	maxrow = 0
	for b in range(m):
		if matrix[i - 1][b] == 1:
			maxrow += 1
			if maxrow > maxmax:
				maxmax = maxrow
		else:
			maxrow = 0
	maxperrow[i - 1] = maxmax
	winner.append(max(maxperrow))
for w in winner:
	print(w)


(r, c, g) = map(int, input().split())
board = []
scores = []
for i in range(r):
	board.append([int(x) for x in input().split()])
	curr = 0
	m = 0
	for num in board[-1]:
		if num == 1:
			curr += 1
		else:
			m = max(m, curr)
			curr = 0
	m = max(m, curr)
	scores.append(m)
for i in range(g):
	(x, y) = map(int, input().split())
	x -= 1
	y -= 1
	if board[x][y]:
		board[x][y] = 0
	else:
		board[x][y] = 1
	curr = 0
	m = 0
	for num in board[x]:
		if num == 1:
			curr += 1
		else:
			m = max(m, curr)
			curr = 0
	m = max(m, curr)
	scores[x] = m
	print(max(scores))


(n, m, q) = map(int, input().split())
ma = []
for i in range(n):
	l1 = list(map(int, input().split()))
	ma.append(l1)
gma = 0
lstgrt = [0] * n
for i in range(n):
	lma = 0
	gma = 0
	for j in range(m):
		if ma[i][j] == 1:
			lma = lma + 1
		else:
			if lma > gma:
				gma = lma
			lma = 0
	if lma > gma:
		gma = lma
		lma = 0
	lstgrt[i] = gma
for u in range(q):
	(a, b) = map(int, input().split())
	a = a - 1
	b = b - 1
	if ma[a][b] == 1:
		ma[a][b] = 0
	else:
		ma[a][b] = 1
	lma = 0
	gma = 0
	i = a
	for j in range(m):
		if ma[i][j] == 1:
			lma = lma + 1
		else:
			if lma > gma:
				gma = lma
			lma = 0
	if lma > gma:
		gma = lma
		lma = 0
	lstgrt[i] = gma
	print(max(lstgrt))


def func(a):
	ans = 0
	an = 0
	for i in a:
		if i == 0:
			ans = max(ans, an)
			an = 0
		else:
			an += 1
	return max(ans, an)
(n, m, q) = (int(x) for x in input().split(' '))
a = [[int(x) for x in input().split()] for i in range(n)]
mas = [func(a[i]) for i in range(n)]
for _ in range(q):
	(x, y) = (int(i) - 1 for i in input().split(' '))
	a[x][y] = 1 if a[x][y] == 0 else 0
	mas[x] = func(a[x])
	print(max(mas))


def line_score(row):
	m = 0
	c = 0
	for elem in row:
		if elem == 1:
			c += 1
		else:
			c = 0
		m = max(c, m)
	return m
(n, m, q) = [int(x) for x in input().split(' ')]
grid = [[int(x) for x in input().split(' ')] for row in range(n)]
rounds = [[int(x) for x in input().split(' ')] for round in range(q)]
z = []
for row in grid:
	z.append(line_score(row))
for round in rounds:
	(i, j) = round
	grid[i - 1][j - 1] = 1 - grid[i - 1][j - 1]
	z[i - 1] = line_score(grid[i - 1])
	print(max(z))


(n, m, q) = map(int, input().split())
matrix = []
for i in range(n):
	matrix.append(list(map(int, input().split())))
dp = [0 for j in range(n)]
for i in range(n):
	streak = 0
	z = 0
	for j in range(m):
		if matrix[i][j] == 1:
			streak = streak + 1
			z = max(streak, z)
		else:
			z = max(streak, z)
			streak = 0
	dp[i] = z
for i in range(q):
	(x, y) = map(int, input().split())
	matrix[x - 1][y - 1] = 1 - matrix[x - 1][y - 1]
	z = float('-inf')
	streak = 0
	for i in range(m):
		if matrix[x - 1][i] == 1:
			streak = streak + 1
			z = max(streak, z)
		else:
			z = max(streak, z)
			streak = 0
	dp[x - 1] = z
	print(max(dp))