#yukicoder 旅行会社 class UnionFind(): def __init__(self, n): self.n = n self.parents = [-1] *(n) #parents 各要素の親番号を格納するリストを返す #要素xが属するグループを返す def find(self, x): if self.parents[x] < 0: return x else: self.parents[x] = self.find(self.parents[x]) return self.parents[x] #要素xとyが属するグループを併合する 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 #要素xが属するグループのサイズ def size(self, x): return -self.parents[self.find(x)] #要素xとyが同じグループに属するかどうか def same(self, x, y): return self.find(x) == self.find(y) #要素xが属するグループを返す def members(self, x): root = self.find(x) return [i for i in range(self.n) if self.find(i) == root] #すべての根の要素 def roots(self): return [i for i, x in enumerate(self.parents) if x < 0] #グループの数 def group_count(self): return len(self.roots()) def all_group_members(self): return {r: self.members(r) for r in self.roots()} from sys import stdin input = stdin.readline def main(): N,M,Q = map(int,input().split()) uf = UnionFind(N) m = map(int, input().split()) ABCD = tuple(zip(m, m)) AB = ABCD[:M] CD = ABCD[M:] init_set = set(AB)-set(CD) for a,b in init_set: uf.union(a,b) for i in range(len(CD[::-1])): c, d = CD[::-1][i] if uf.same(c,0) and uf.same(d,0): continue elif uf.same(d,0) and not uf.same(c,0): res[c-1] = M -i elif uf.same(c,0) and not uf.same(d,0): res[d-1] = M-i uf.union(c,d) for i in res: print(i) main()