N,M,Q=map(int,input().split()) E=[tuple(map(int,input().split())) for i in range(M)] E2=[tuple(map(int,input().split())) for i in range(Q)] # UnionFind Group = [i for i in range(N+1)] # グループ分け Nodes = [1]*(N+1) # 各グループのノードの数 def find(x): while Group[x] != x: x=Group[x] return x def Union(x,y): if find(x) != find(y): if Nodes[find(x)] < Nodes[find(y)]: Nodes[find(y)] += Nodes[find(x)] Nodes[find(x)] = 0 Group[find(x)] = find(y) else: Nodes[find(x)] += Nodes[find(y)] Nodes[find(y)] = 0 Group[find(y)] = find(x) EDGE=[[] for i in range(N+1)] for x,y in set(E)-set(E2): EDGE[x].append(y) EDGE[y].append(x) Union(x,y) ANS=[-1]*(N+1) Q=[1] while Q: x=Q.pop() ANS[x]=0 for to in EDGE[x]: if ANS[to]==-1: ANS[to]=0 Q.append(to) #print(ANS) for i in range(len(E2)-1,-1,-1): x,y = E2[i] Union(x,y) EDGE[x].append(y) EDGE[y].append(x) if ANS[x]==-1 and find(x)==find(1): Q=[x] while Q: x=Q.pop() ANS[x]=i+1 for to in EDGE[x]: if ANS[to]==-1: ANS[to]=i+1 Q.append(to) if ANS[y]==-1 and find(y)==find(1): Q=[y] while Q: x=Q.pop() ANS[x]=i+1 for to in EDGE[x]: if ANS[to]==-1: ANS[to]=i+1 Q.append(to) #print(i,ANS) for i in range(N+1): if ANS[i]==0: ANS[i]=-1 if find(i)!=find(1): ANS[i]=0 for a in ANS[2:]: print(a)