class UnionFind: def __init__(self, n): self.node = [-1 for _ in range(n)] def root(self, v): if self.node[v] < 0: return v st = [] while self.node[v] >= 0: st.append(v) v = self.node[v] for u in st: self.node[u] = v return v def size(self, v): v = self.root(v) return (- self.node[v]) def same(self, u, v): return self.root(u) == self.root(v) def unite(self, u, v): ru = self.root(u) rv = self.root(v) if ru == rv: return du = self.node[ru] dv = self.node[rv] if du <= dv: self.node[rv] = ru self.node[ru] += dv else: self.node[ru] = rv self.node[rv] += du n, m, q = map(int, input().split()) edges = [] idx = {} for _ in range(m): a, b = map(int, input().split()) a -= 1 b -= 1 edges.append((a, b)) idx[a, b] = len(idx) queries = [] for _ in range(q): c, d = map(int, input().split()) c -= 1 d -= 1 queries.append(idx[c, d]) es = set([i for i in range(m)]) - set(queries) uf = UnionFind(n) comps = [[] for _ in range(n)] for e in es: a, b = edges[e] uf.unite(a, b) for v in range(n): r = uf.root(v) comps[r].append(v) ans = [None for _ in range(n)] for v in comps[0]: ans[v] = -1 for i in range(q - 1, -1, -1): c, d = edges[queries[i]] rc = uf.root(c) rd = uf.root(d) if rc == rd: continue r0 = uf.root(0) if r0 == rc: for v in comps[rd]: ans[v] = i + 1 elif r0 == rd: for v in comps[rc]: ans[v] = i + 1 uf.unite(rc, rd) r = uf.root(rc) while len(comps[rc + rd - r]) > 0: comps[r].append(comps[rc + rd - r].pop()) for v in range(n): if ans[v] is None: ans[v] = 0 print(*ans[1:], sep="\n")