#include using namespace std; struct DSU { vector fa, rank; DSU(int n) : fa(n), rank(n, 1) { iota(fa.begin(), fa.end(), 0); } int find(int x) { return fa[x] == x ? x : fa[x] = find(fa[x]); } void unite(int x, int y) { x = find(x), y = find(y); if (x == y) return; if (rank[x] < rank[y]) swap(x, y); fa[y] = x, rank[x] += rank[y]; } bool same(int x, int y) { return find(x) == find(y); } }; int main() { freopen("evacuate.in", "r", stdin); freopen("evacuate.out", "w", stdout); int n, m, q; cin >> n >> m >> q; set> edges; vector ans(n, -1), rX(q), rY(q); vector> scc(n); DSU uf(n); for (int i = 0, x, y; i < m; i++) { cin >> x >> y; edges.emplace(x - 1, y - 1); } for (int i = 0; i < q; i++) { cin >> rX[i] >> rY[i]; rX[i]--, rY[i]--, edges.erase({rX[i], rY[i]}); } for (const auto& [x, y] : edges) uf.unite(x, y); for (int i = 0; i < n; i++) scc[uf.find(i)].push_back(i); for (int i = 0; i < n; i++) if (uf.same(0, i)) ans[i] = -1; for (int i = q - 1; i >= 0; i--) { int x = uf.find(rX[i]), y = uf.find(rY[i]); if (x != y) { if (uf.same(0, x)) for (int node : scc[y]) ans[node] = i + 1; else if (uf.same(0, y)) for (int node : scc[x]) ans[node] = i + 1; // merge if (scc[x].size() < scc[y].size()) swap(x, y); scc[x].insert(scc[x].end(), scc[y].begin(), scc[y].end()); scc[y].clear(); uf.unite(x, y); } } for (int i = 1; i < n; i++) cout << ans[i] << endl; }