import java.util.*; public class Main { Scanner cin; int N, M, Q; int[] A, B, C, D, ret; boolean[] V; List< HashMap< Integer, Integer > > edgeIdx; UnionFind tree; List< Queue < Integer > > que; public static void main(String[] arg) { new Main().Solve(); } public void Solve() { cin = new Scanner(System.in); N = cin.nextInt(); M = cin.nextInt(); Q = cin.nextInt(); A = new int[M]; B = new int[M]; C = new int[Q]; D = new int[Q]; ret = new int[N]; V = new boolean[M]; edgeIdx = new ArrayList<>(); for(int i = 0; i < N; i++) { edgeIdx.add(new HashMap<>()); } tree = new UnionFind(N); que = new ArrayList<>(); for(int i = 0; i < N; i++) { que.add(new ArrayDeque< Integer >()); que.get(i).add(i); } for(int i = 0; i < M;i++) { A[i] = cin.nextInt() - 1; B[i] = cin.nextInt() - 1; edgeIdx.get(A[i]).put(B[i], i); } for(int i = 0; i < Q; i++) { C[i] = cin.nextInt() - 1; D[i] = cin.nextInt() - 1; V[edgeIdx.get(C[i]).get(D[i])] = true; } for(int i = 0; i < M; i++) { if(!V[i]) Merge(A[i], B[i]); } int root = tree.find(0); while(!que.get(root).isEmpty()) { ret[que.get(root).poll()] = -1; } for(int i = Q - 1; i >= 0; i--) { Merge(C[i], D[i]); root = tree.find(0); while(!que.get(root).isEmpty()) { ret[que.get(root).poll()] = i + 1; } } for(int i = 1; i < N; i++) { System.out.println(ret[i]); } } public void Merge(int p, int q) { p = tree.find(p); q = tree.find(q); if(p != q) { if(que.get(p).size() < que.get(q).size()) { while(!que.get(p).isEmpty()) { que.get(q).add(que.get(p).poll()); } tree.unite(q, p); } else { while(!que.get(q).isEmpty()) { que.get(p).add(que.get(q).poll()); } tree.unite(p, q); } } return; } public class UnionFind { int[] data; UnionFind(int sz) { data = new int[sz]; Arrays.fill(data, -1); } int find(int y) { if(data[y] < 0) return(y); return(data[y] = find(data[y])); } int unite(int x, int y) { x = find(x); y = find(y); if(x != y) { data[x] += data[y]; data[y] = x; } return(find(x)); } } }