#include <bits/stdc++.h>
using namespace std;
const long long mod = 998244353;
const long long N = 3e5 + 5;
const double eps = 1e-8;
const double PI = acos(-1);
long long gcd(long long a, long long b) { return !b ? a : gcd(b, a % b); }
long long re() {
  long long x;
  scanf("%lld", &x);
  return x;
}
long long qk(long long a, long long b) {
  long long ans = 1;
  while (b) {
    if (b & 1) ans = ans * a % mod;
    a = a * a % mod;
    b /= 2;
  }
  return ans;
}
int dx[8] = {1, 0, -1, 0, 1, 1, -1, -1}, dy[8] = {0, 1, 0, -1, 1, -1, 1, -1};
int a[N], b[N];
vector<int> v1, v2;
int fina(int x) { return a[x] = a[x] == x ? x : fina(a[x]); }
int finb(int x) { return b[x] = b[x] == x ? x : finb(b[x]); }
void solve() {
  int n, m1, m2;
  cin >> n >> m1 >> m2;
  for (int i = 1; i <= n; i++) a[i] = i, b[i] = i;
  int x, y;
  for (int i = 1; i <= m1; i++) {
    scanf("%d%d", &x, &y);
    a[fina(x)] = fina(y);
  }
  for (int i = 1; i <= m2; i++) {
    scanf("%d%d", &x, &y);
    b[finb(x)] = finb(y);
  }
  vector<pair<int, int> > v;
  for (int i = 1; i <= 1; i++) {
    for (int j = i + 1; j <= n; j++) {
      if (fina(i) != fina(j) && finb(i) != finb(j)) {
        a[fina(i)] = fina(j);
        b[finb(i)] = finb(j);
        v.emplace_back(make_pair(i, j));
      }
      if (fina(j) != fina(1)) v1.emplace_back(j);
      if (finb(j) != finb(1)) v2.emplace_back(j);
    }
  }
  for (int i = 0, j = 0; i < v1.size() && j < v2.size();) {
    if (fina(v1[i]) == fina(1) && finb(v1[i]) == finb(1)) {
      i++;
      continue;
    }
    if (fina(v2[j]) == fina(1) && finb(v2[j]) == finb(1)) {
      j++;
      continue;
    }
    a[fina(v1[i])] = fina(v2[j]);
    b[finb(v1[i])] = finb(v2[j]);
    v.emplace_back(v1[i], v2[j]);
  }
  cout << v.size() << '\n';
  for (int i = 0; i < v.size(); i++) {
    printf("%d %d\n", v[i].first, v[i].second);
  }
}
int main() {
  int T = 1;
  while (T--) solve();
  return 0;
}
