class UnionFind2: def __init__(self, n): self.n = n self.parents = [-1] * n self.family = [{i} for i in range(n)] def find(self, x): if self.parents[x] < 0: return x else: self.parents[x] = self.find(self.parents[x]) return self.parents[x] def union(self, x, y): x = self.find(x) y = self.find(y) if x == y: return if self.parents[x] > self.parents[y]: x, y = y, x self.parents[x] += self.parents[y] self.parents[y] = x self.family[x] |= self.family[y] self.family[y] = {} def same(self,i,j): return uf.find(i) == uf.find(j) def size(self, x): return -self.parents[self.find(x)] n,m,h=map(int,input().split()) ms=[tuple(map(int,input().split())) for i in range(m)] hs=[tuple(map(int,input().split())) for i in range(h)] shs = set(hs) uf = UnionFind2(n+1) for i in range(m): if ms[i] not in shs: uf.union(ms[i][0],ms[i][1]) ans = [0]*(n+1) for i in range(2,n+1): if uf.same(1,i): ans[i] = -1 cnt = h for i,j in hs[::-1]: if uf.same(i,j): #ここでもマイナス cnt-=1 continue #もしiと1が連結ならば 上でi,jが連結でないことがわかっているので #1とj集合は連結でないよってj集合は新たに1とつながる #ここでansに破壊時刻を記憶 unionの時に実際にマージする #family[] は xではなく find(x) if i in uf.family[uf.find(1)]: for k in uf.family[uf.find(j)]: ans[k] = cnt if j in uf.family[uf.find(1)]: for k in uf.family[uf.find(i)]: ans[k] = cnt uf.union(i,j) cnt-=1 for i in range(2,n+1): print(ans[i])