#include "bits/stdc++.h" using namespace std; using ll = long long; using ld = long double; const int INF = (1 << 30) - 1; const ll INF64 = ((ll)1 << 62) - 1; const double PI = 3.1415926535897932384626433832795; const int dx[] = { 0, 1, 0, -1 }; const int dy[] = { -1, 0, 1, 0 }; int main() { ios::sync_with_stdio(false); cin.tie(0); int n, m, q; cin >> n >> m >> q; vector> g(n); for (int i = 0; i < m; i++) { ll a, b; cin >> a >> b; a--; b--; g[a][b] = g[b][a] = INF; } for (int i = 0; i < q; i++) { int c, d; cin >> c >> d; c--; d--; g[c][d] = g[d][c] = i + 1; } priority_queue> pq; vector ans(n); ans[0] = INF; pq.emplace(INF, 0); vector used(n); while (!pq.empty()) { int c = pq.top().first; int i = pq.top().second; pq.pop(); if (used[i]) { continue; } used[i] = true; for (auto p : g[i]) { int j = p.first; int cc = p.second; if (ans[j] < min(ans[i], cc)) { ans[j] = min(ans[i], cc); pq.emplace(ans[j], j); } } } for (int i = 1; i < n; i++) { cout << (ans[i] == INF ? -1 : ans[i]) << endl; } return 0; }