import sys input = sys.stdin.readline class Unionfind: def __init__(self, n): self.par = [-1]*n self.rank = [1]*n self.belong = [[v] for v in range(n)] def root(self, x): r = x while not self.par[r]<0: r = self.par[r] t = x while t!=r: tmp = t t = self.par[t] self.par[tmp] = r return r def unite(self, x, y): rx = self.root(x) ry = self.root(y) if rx==ry: return if self.rank[rx]<=self.rank[ry]: self.par[ry] += self.par[rx] self.par[rx] = ry if self.rank[rx]==self.rank[ry]: self.rank[ry] += 1 self.belong[ry] += self.belong[rx] else: self.par[rx] += self.par[ry] self.par[ry] = rx self.belong[rx] += self.belong[ry] def is_same(self, x, y): return self.root(x)==self.root(y) def count(self, x): return -self.par[self.root(x)] N, M, Q = map(int, input().split()) AB = [tuple(map(int, input().split())) for _ in range(M)] CD = [tuple(map(int, input().split())) for _ in range(Q)] s = set(10**7*C+D for C, D in CD) uf = Unionfind(N) for A, B in AB: if 10**7*A+B not in s: uf.unite(A-1, B-1) ans = [0]*N for v in uf.belong[uf.root(0)]: ans[v] = -1 for i in range(Q-1, -1, -1): C, D = CD[i] if uf.is_same(0, C-1) and not uf.is_same(0, D-1): for v in uf.belong[uf.root(D-1)]: ans[v] = i+1 elif uf.is_same(0, D-1) and not uf.is_same(0, C-1): for v in uf.belong[uf.root(C-1)]: ans[v] = i+1 uf.unite(C-1, D-1) for ans_i in ans[1:]: print(ans_i)