#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 7;
int rd() {
  int s = 0, f = 1;
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    s = s * 10 + c - '0';
    c = getchar();
  }
  return s * f;
}
int n, m1, m2, k, tot, fa[2][maxn];
vector<pair<int, int> > ans;
int get(int x, int num) {
  return fa[num][x] == x ? x : fa[num][x] = get(fa[num][x], num);
}
int S[maxn], stop;
int T[maxn], ttop;
int main() {
  n = rd();
  for (int i = 1; i <= n; i++) fa[0][i] = fa[1][i] = i;
  m1 = rd(), m2 = rd();
  for (int i = 1, u, v; i <= m1; i++) {
    u = rd();
    v = rd();
    u = get(u, 0), v = get(v, 0);
    if (u > v) fa[0][u] = v;
    if (u < v) fa[0][v] = u;
  }
  for (int i = 1, u, v; i <= m2; i++) {
    u = rd();
    v = rd();
    u = get(u, 1), v = get(v, 1);
    if (u > v) fa[1][u] = v;
    if (u < v) fa[1][v] = u;
  }
  for (int i = 2; i <= n; i++) {
    int f0 = get(i, 0), f1 = get(i, 1);
    if (f0 != 1 && f1 != 1) {
      fa[0][f0] = 1;
      fa[1][f1] = 1;
      tot++;
      ans.push_back(make_pair(i, 1));
    }
  }
  for (int i = 2, j = 2; i <= n; i++) {
    int f0 = get(i, 0);
    if (f0 != 1) {
      int f1 = get(j, 1);
      while (f1 == 1 && j <= n) {
        f1 = get(++j, 1);
      }
      if (j > n) break;
      fa[0][f0] = 1;
      fa[1][f1] = 1;
      tot++;
      ans.push_back(make_pair(i, j));
    }
  }
  printf("%d\n", tot);
  for (int i = 0; i < tot; i++) {
    printf("%d %d\n", ans[i].first, ans[i].second);
  }
}
