#include <bits/stdc++.h>
using namespace std;
const int N = 100010;
int a[N], b[N], n, m1, m2;
int fina(int x) { return a[x] == x ? x : a[x] = fina(a[x]); }
int finb(int x) { return b[x] == x ? x : b[x] = finb(b[x]); }
int main() {
  cin >> n >> m1 >> m2;
  for (int i = 1; i <= n; i++) a[i] = b[i] = i;
  while (m1--) {
    int x, y;
    cin >> x >> y;
    int fx = fina(x), fy = fina(y);
    if (fx != fy) a[fx] = fy;
  }
  while (m2--) {
    int x, y;
    cin >> x >> y;
    int fx = finb(x), fy = finb(y);
    if (fx != fy) b[fx] = fy;
  }
  vector<pair<int, int> > res;
  vector<int> v1, v2;
  for (int j = 2; j <= n; j++) {
    if (fina(1) != fina(j) && finb(1) != finb(j)) {
      a[fina(j)] = fina(1);
      b[finb(j)] = finb(1);
      res.push_back({1, j});
    } else if (fina(1) != fina(j))
      v1.push_back(j);
    else if (finb(1) != finb(j))
      v2.push_back(j);
  }
  int i = 0, j = 0;
  while (i < v1.size() && j < v2.size()) {
    int x = v1[i], y = v2[j];
    if (fina(x) != fina(y) && finb(x) != finb(y)) {
      res.push_back({x, y});
      a[fina(x)] = fina(y);
      b[finb(x)] = finb(y);
      i++, j++;
    } else {
      if (fina(x) == fina(y)) i++;
      if (finb(x) == finb(y)) j++;
    }
  }
  cout << res.size() << endl;
  for (auto &[u, v] : res) cout << u << ' ' << v << endl;
}
