import copy class UnionFind(object): def __init__(self, n): self.uf = [-1 for _ in xrange(n)] self.sets = {0:set([0])} def union(self, x, y): x = self.find(x) y = self.find(y) if x == y: return [] if self.uf[x] >= self.uf[y]: if self.uf[x] == self.uf[y] == -1: self.sets[y] = set([x, y]) elif self.uf[x] == -1: self.sets[y].add(x) else: self.sets[y] |= self.sets[x] self.uf[y] += self.uf[x] self.uf[x] = y return self.sets[y] else: if self.uf[y] == -1: self.sets[x].add(y) else: self.sets[x] |= self.sets[y] self.uf[x] += self.uf[y] self.uf[y] = x return self.sets[x] def find(self, x): leaves = [] while self.uf[x] >= 0: leaves.append(x) x = self.uf[x] for lf in leaves: self.uf[lf] = x return x N, M, Q = map(int, raw_input().split()) AB = set([tuple(map(lambda x:int(x)-1, raw_input().split())) for _ in xrange(M)]) CD = [tuple(map(lambda x:int(x)-1, raw_input().split())) for _ in xrange(Q)] AB -= set(CD) uf = UnionFind(N) for a, b in AB: uf.union(a, b) ans = [-1 for _ in xrange(N)] old_set = set(uf.sets[uf.find(0)]) print old_set for i in xrange(Q-1, -1, -1): c, d = CD[i] uf.union(c, d) new_set = uf.sets[uf.find(0)] for j in new_set - old_set: ans[j] = i+1 old_set = copy.copy(new_set) for i in xrange(1, N): print ans[i]