#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const int mx = 1e5 + 9;
struct DSU {
  int par[mx];
  DSU() {
    for (int i = 1; i < mx; i++) par[i] = i;
  }
  int fnd(int x) {
    if (x == par[x]) return x;
    return par[x] = fnd(par[x]);
  }
  void join(int u, int v) {
    int pu = fnd(u), pv = fnd(v);
    if (pu == pv) return;
    par[pu] = pv;
  }
} mocha, diana;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  ;
  int n, m1, m2;
  cin >> n >> m1 >> m2;
  while (m1--) {
    int u, v;
    cin >> u >> v;
    mocha.join(u, v);
  }
  while (m2--) {
    int u, v;
    cin >> u >> v;
    diana.join(u, v);
  }
  vector<pii> ans;
  stack<int> p1, p2;
  for (int i = 2; i <= n; i++) {
    if (mocha.fnd(i) == mocha.fnd(1)) {
      p1.push(i);
      continue;
    }
    if (diana.fnd(i) == diana.fnd(1)) {
      p2.push(i);
      continue;
    }
    mocha.join(i, 1);
    diana.join(i, 1);
    ans.push_back({i, 1});
    p1.push(i);
    p2.push(i);
  }
  while (true) {
    if (p1.empty()) break;
    if (p2.empty()) break;
    if (mocha.fnd(p1.top()) == mocha.fnd(1) and
        diana.fnd(p1.top()) == diana.fnd(1)) {
      p1.pop();
      continue;
    }
    if (mocha.fnd(p2.top()) == mocha.fnd(1) and
        diana.fnd(p2.top()) == diana.fnd(1)) {
      p2.pop();
      continue;
    }
    int u = p1.top();
    int v = p2.top();
    ans.push_back({u, v});
    mocha.join(u, v);
    diana.join(u, v);
  }
  cout << ans.size() << '\n';
  for (auto [u, v] : ans) cout << u << " " << v << '\n';
}
