import java.util.*; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int m = sc.nextInt(); int q = sc.nextInt(); Bridge[] org = new Bridge[m]; for (int i = 0; i < m; i++) { org[i] = new Bridge(sc.nextInt() - 1, sc.nextInt() - 1); } HashSet broken = new HashSet<>(); Bridge[] breaking = new Bridge[q]; for (int i = 0; i < q; i++) { breaking[i] = new Bridge(sc.nextInt() - 1, sc.nextInt() - 1); broken.add(breaking[i]); } ArrayList> graph = new ArrayList<>(); for (int i = 0; i < n; i++) { graph.add(new ArrayList<>()); } UnionFindTree uft = new UnionFindTree(n); for (Bridge b : org) { if (!broken.contains(b)) { uft.unite(b); graph.get(b.left).add(b.right); graph.get(b.right).add(b.left); } } boolean[] visited = new boolean[n]; int[] ans = new int[n]; ArrayDeque deq = new ArrayDeque<>(); deq.add(0); while (deq.size() > 0) { int x = deq.poll(); if (visited[x]) { continue; } visited[x] = true; ans[x] = -1; deq.addAll(graph.get(x)); } for (int i = q - 1; i >= 0; i--) { if (uft.same(breaking[i])) { continue; } if (uft.same(0, breaking[i].left)) { deq.add(breaking[i].right); } else if (uft.same(0, breaking[i].right)) { deq.add(breaking[i].left); } while (deq.size() > 0) { int x = deq.poll(); if (visited[x]) { continue; } visited[x] = true; ans[x] = i + 1; deq.addAll(graph.get(x)); } uft.unite(breaking[i]); graph.get(breaking[i].left).add(breaking[i].right); graph.get(breaking[i].right).add(breaking[i].left); } StringBuilder sb = new StringBuilder(); for (int i = 1; i < n; i++) { sb.append(ans[i]).append("\n"); } System.out.print(sb); } static class UnionFindTree { int[] parents; public UnionFindTree(int size) { parents = new int[size]; for (int i = 0; i < size; i++) { parents[i] = i; } } public int find(int x) { if (parents[x] == x) { return x; } else { return parents[x] = find(parents[x]); } } public boolean same(int x, int y) { return find(x) == find(y); } public boolean same(Bridge b) { return same(b.left, b.right); } public void unite(int x, int y) { if (!same(x, y)) { parents[find(x)] = find(y); } } public void unite(Bridge b) { unite(b.left, b.right); } } static class Bridge { int left; int right; public Bridge(int left, int right) { this.left = left; this.right = right; } public int hashCode() { return left; } public boolean equals(Object o) { Bridge b = (Bridge)o; return left == b.left && right == b.right; } } }