#include using namespace std; using ll = long long; using ull = unsigned long long; using ld = long double; template using vc = vector; template using vvc = vc>; using pi = pair; using pl = pair; using vi = vc; using vvi = vvc; using vl = vc; using vvl = vvc; #define rep(i,a,b) for (int i = (int)(a); i < (int)(b); i++) #define irep(i,a,b) for (int i = (int)(a); i > (int)(b); i--) #define all(a) a.begin(),a.end() #define print(n) cout << n << '\n' #define pritn(n) print(n) #define printv(n,a) {copy(all(n),ostream_iterator(cout," ")); cout<<"\n";} #define printvv(n,a) {for(auto itr:n) printv(itr,a);} #define rup(a,b) (a+b-1)/b #define input(A,N) rep(i,0,N) cin>>A[i] #define chmax(a,b) a = max(a,b) #define chmin(a,b) a = min(a,b) struct unionfind{ int n; vector parent; vector num; unionfind(int n):n(n),parent(vector(n)),num(vector(n,1)){ for(int i = 0; i < n; i++) parent[i] = i; } int find(int n){ if (parent[n] == n) return n; parent[n] = find(parent[n]); return parent[n]; } int merge(int n,int m){ n = find(n); m = find(m); if (n==m) return n; if (num[n]>num[m]) return merge(m,n); parent[m] = n; num[n] += num[m]; return n; } int getnum(int n){ return num[find(n)]; } }; int dfs(vi&ans,vi&now,int ni){ if(ans[now[ni]] != -1){ ans[ni] = ans[now[ni]]; return ans[ni]; } return ans[ni] = dfs(ans,now,now[ni]); } int main(){ cout << fixed << setprecision(15); int n,m,q; cin>>n>>m>>q; unionfind uf(n); vi a(m),b(m); rep(i,0,m){ cin>>a[i]>>b[i]; a[i]--;b[i]--; } vi c(q),d(q); rep(i,0,q){ cin>>c[i]>>d[i]; c[i]--;d[i]--; } set s; rep(i,0,m)s.insert(pi(a[i],b[i])); rep(i,0,q)s.erase(pi(c[i],d[i])); for(auto now:s){ uf.merge(now.first,now.second); } vi ans(n,-2); vi now(n,0); rep(i,0,n) now[i] = uf.find(i); rep(i,0,n){ if(uf.find(i)==uf.find(0)) ans[i] = -1; } irep(i,q-1,-1){ int ni = c[i]; int mi = d[i]; ni = uf.find(ni); mi = uf.find(mi); if(ni==mi) continue; if(ni!=uf.find(0)&&mi!=uf.find(0)){ uf.merge(ni,mi); now[mi] = ni; continue; } if(mi==uf.find(0)) swap(ni,mi); ans[mi] = i + 1; now[mi] = ni; uf.merge(ni,mi); } ans[0] = 0; rep(i,0,n){ if(ans[i]!=-2) continue; if(uf.find(i)!=uf.find(0)){ ans[i] = -1; continue; } dfs(ans,now,i); } rep(i,1,n) print(ans[i]); //system("pause"); return 0; }