#include <bits/stdc++.h>
using namespace std;
int f(vector<int>& a, int x) {
  if (a[x] == x) return x;
  a[x] = f(a, a[x]);
  return a[x];
}
bool mer(vector<int>& a, int x, int y) {
  if (f(a, x) == f(a, y))
    return true;
  else
    return false;
}
void uni(vector<int>& a, int x, int y) {
  if (mer(a, x, y))
    return;
  else
    a[f(a, y)] = f(a, x);
}
bool s[100005];
int main() {
  int n, ma, mb, x, y;
  cin >> n >> ma >> mb;
  vector<int> a(n + 1), b(n + 1);
  for (int i = 0; i <= n; i++) a[i] = b[i] = i;
  for (int i = 0; i < ma; i++) {
    cin >> x >> y;
    uni(a, x, y);
  }
  for (int i = 0; i < mb; i++) {
    cin >> x >> y;
    uni(b, x, y);
  }
  vector<pair<int, int>> c;
  vector<int> e, f;
  for (int i = 1; i <= n; i++) {
    if (!mer(a, 1, i) && !mer(b, 1, i)) {
      c.push_back(pair<int, int>(1, i));
      uni(a, 1, i);
      uni(b, 1, i);
    }
  }
  int i, j;
  i = j = 2;
  while (1) {
    while (i <= n && mer(a, 1, i)) i++;
    if (i > n) break;
    while (j <= n && mer(b, 1, j)) j++;
    if (j > n) break;
    uni(a, i, j);
    uni(b, i, j);
    c.push_back(pair<int, int>(i, j));
    i++;
    j++;
  }
  cout << c.size() << endl;
  for (int i = 0; i < c.size(); i++) {
    cout << c[i].first << " " << c[i].second << endl;
  }
  return 0;
}
