class UnionFind:
    def __init__(self, n):
        self.par = [i for i in range(n+1)]
        self.rank = [0] * (n + 1)
        self.size = [1] * (n + 1)

    # 検索
    def find(self, x):
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]

    # 併合
    def unite(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return
        if self.rank[x] < self.rank[y]:
            self.par[x] = y
            self.size[y] += self.size[x]
        else:
            self.par[y] = x
            self.size[x] += self.size[y]
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1

    # 同じ集合に属するか判定
    def same_check(self, x, y):
        return self.find(x) == self.find(y)


n, m, q = map(int, input().split())
s = [list(map(int, input())) for _ in range(n)]
uf = UnionFind(n * 7)
g = [[] for _ in range(n)]
for i in range(m):
    u, v = map(int, input().split())
    g[u - 1].append(v - 1)
    g[v - 1].append(u - 1)
for i in range(n * 7):
    v, c = i // 7, i % 7
    if s[v][c]:
        if s[v][(c + 1) % 7]:
            uf.unite(i, v * 7 + (c + 1) % 7)
        if s[v][(c - 1) % 7]:
            uf.unite(i, v * 7 + (c - 1) % 7)
        for node in g[v]:
            if s[node][c]:
                uf.unite(i, node * 7 + c)
for _ in range(q):
    t, x, y = map(int, input().split())
    x -= 1
    y -= 1
    if t == 1:
        s[x][y] = 1
        for node in g[x]:
            if s[node][y]:
                uf.unite(x * 7 + y, node * 7 + y)
        if s[x][(y + 1) % 7]:
            uf.unite(x * 7 + y, x * 7 + (y + 1) % 7)
        if s[x][(y - 1) % 7]:
            uf.unite(x * 7 + y, x * 7 + (y - 1) % 7)
    else:
        print(uf.size[uf.find(x * 7)])