package No400番台; import java.util.ArrayDeque; import java.util.ArrayList; import java.util.Arrays; import java.util.Scanner; public class Q416 { public static void main(String[] args) { new Q416().solver(); } @SuppressWarnings("unchecked") void solver() { Scanner sc = new Scanner(System.in); int N = sc.nextInt();// the number of islands int M = sc.nextInt();// the number of bridges int Q = sc.nextInt();// the number of events ArrayList[] g = new ArrayList[N]; for (int i = 0; i < N; i++) { g[i] = new ArrayList<>(); } ArrayList[] ref = new ArrayList[N]; for (int i = 0; i < N; i++) { ref[i] = new ArrayList<>(); } int[] A = new int[M]; int[] B = new int[M]; for (int i = 0; i < M; i++) { A[i] = sc.nextInt() - 1; B[i] = sc.nextInt() - 1; } int[] C = new int[Q]; int[] D = new int[Q]; for (int i = 0; i < Q; i++) { C[i] = sc.nextInt() - 1; D[i] = sc.nextInt() - 1; ref[C[i]].add(D[i]); ref[D[i]].add(C[i]); g[C[i]].add(new Edge(C[i], D[i], i + 1)); g[D[i]].add(new Edge(D[i], C[i], i + 1)); } for (int i = 0; i < M; i++) { if (ref[A[i]].contains(B[i])) continue; g[A[i]].add(new Edge(A[i], B[i], Q + 1)); g[B[i]].add(new Edge(B[i], A[i], Q + 1)); } ArrayDeque que = new ArrayDeque<>(); ArrayDeque[] pending = new ArrayDeque[Q + 1]; for (int i = 0; i < Q + 1; i++) pending[i] = new ArrayDeque<>(); que.add(0); int[] d = new int[N]; boolean[] checked = new boolean[N]; while (!que.isEmpty()) { int v = que.poll(); d[v] = Q + 1; checked[v] = true; for (Edge e : g[v]) { if (checked[e.dst]) continue; if (e.event_time == Q + 1) { que.add(e.dst); } else { pending[e.event_time].add(e.dst); } } } for (int i = Q; i >= 1; i--) { while (!pending[i].isEmpty()) { que.add(pending[i].poll()); while (!que.isEmpty()) { int v = que.poll(); if (checked[v]) continue; d[v] = i; checked[v] = true; for (Edge e : g[v]) { if (checked[e.dst]) continue; if (e.event_time >= i) { que.add(e.dst); } else { pending[e.event_time].add(e.dst); } } } } } for (int i = 1; i < N; i++) { if (d[i] == Q + 1) { System.out.println(-1); } else { System.out.println(d[i]); } } } void tr(Object... o) { System.out.println(Arrays.deepToString(o)); } class Edge { int src; int dst; int event_time; Edge(int src, int dst, int event_time) { this.src = src; this.dst = dst; this.event_time = event_time; } } }