/* package whatever; // don't place package name! */ import java.util.*; import java.lang.*; import java.io.*; /* Name of the class has to be "Main" only if the class is public. */ class Main { public static void main (String[] args) throws java.lang.Exception { // your code goes here BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String[] lines = br.readLine().toString().split(" "); int N = Integer.parseInt(lines[0]); int M = Integer.parseInt(lines[1]); int Q = Integer.parseInt(lines[2]); for(int i=0;i ansMap = new HashMap(); for(int i=2;i<=N;i++){ if(pathmap.get(i)==null){ ansMap.put(i,0); }else{ ansMap.put(i,-1); } } for(int i=0;i= 0){ continue; } if(pathmap.get(j)==null){ pathmap = new HashMap>(); search(1); }else{ for(Bridge keys:pathmap.get(j).keySet()){ if(keys.flg == false){ pathmap = new HashMap>(); search(1); break; } } } int ans = ansMap.get(j)==null?-1:ansMap.get(j); if(ans == -1){ HashMap map = pathmap.get(j); if(map==null){ ansMap.put(j,i+1); } } } } // System.out.println(pathmap.get(2).keySet().size()); for(int ss:ansMap.keySet()){ System.out.println(ansMap.get(ss)); } } //島にたどり着くための橋リスト static HashMap> pathmap = new HashMap>(); static void search(int start){ Deque deq = new ArrayDeque(); deq.addFirst(start); while(!deq.isEmpty()){ int s = deq.removeFirst(); if(Bridge.bridgeList.get(s) != null){ for(Bridge next:Bridge.bridgeList.get(s)){ if(next.flg==false){ continue; } int g = (s==next.from)?next.to:next.from; HashMap brg = pathmap.get(g); if(brg == null){ HashMap n_brg = hashClone(pathmap.get(s)); n_brg.put(next,true); pathmap.put(g,n_brg); deq.addFirst(g); } } } } } static HashMap hashClone(HashMap src){ HashMap ret = new HashMap(); if(src==null){ return ret; } for(Bridge key:src.keySet()){ ret.put(key,src.get(key)); } return ret; } static class Bridge{ static HashMap> bridgeList = new HashMap>(); static HashMap bridgeMap = new HashMap(); int from; int to; String str; boolean flg; public Bridge(int f,int t){ this.from = f; this.to = t; this.str = new StringBuilder().append(f).append(" ").append(t).toString(); ArrayList arr = bridgeList.get(f); if(arr == null){ arr = new ArrayList(); bridgeList.put(f,arr); } arr.add(this); this.flg = true; arr = bridgeList.get(t); if(arr == null){ arr = new ArrayList(); bridgeList.put(t,arr); } arr.add(this); bridgeMap.put(str,this); } public static void broke(String st){ bridgeMap.get(st).flg = false; } } }