#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline void read(T &x) {
  T f = 1;
  x = 0;
  char ch = getchar();
  while (0 == isdigit(ch)) {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (0 != isdigit(ch)) x = (x << 1) + (x << 3) + ch - '0', ch = getchar();
  x *= f;
}
template <typename T>
inline void write(T x) {
  if (x < 0) {
    x = ~(x - 1);
    putchar('-');
  }
  if (x > 9) write(x / 10);
  putchar(x % 10 + '0');
}
const int inf = 0x3f3f3f3f;
const int N = 1e6 + 100;
int f1[N], f2[N];
int find1(int x) { return f1[x] == x ? x : f1[x] = find1(f1[x]); }
int find2(int x) { return f2[x] == x ? x : f2[x] = find2(f2[x]); }
bool check1(int x, int y) {
  int xx = find1(x), yy = find1(y);
  if (xx != yy) {
    return true;
  }
  return false;
}
bool check2(int x, int y) {
  int xx = find2(x), yy = find2(y);
  if (xx != yy) {
    return true;
  }
  return false;
}
void merge1(int x, int y) {
  int xx = find1(x), yy = find1(y);
  f1[xx] = yy;
}
void merge2(int x, int y) {
  int xx = find2(x), yy = find2(y);
  f2[xx] = yy;
}
void init() {
  for (int i = 0; i < N; i++) {
    f1[i] = f2[i] = i;
  }
}
int main() {
  init();
  int n, m1, m2;
  cin >> n >> m1 >> m2;
  for (int i = 1; i <= m1; i++) {
    int u, v;
    read(u), read(v);
    merge1(u, v);
  }
  for (int i = 1; i <= m2; i++) {
    int u, v;
    read(u), read(v);
    merge2(u, v);
  }
  vector<pair<int, int>> ans;
  vector<int> rt1, rt2;
  for (int i = 2; i <= n; i++) {
    if (check1(1, i) && check2(1, i)) {
      merge1(1, i), merge2(1, i);
      ans.push_back({1, i});
    }
  }
  for (int i = 2; i <= n; i++) {
    if (find1(i) == i && check1(1, i)) {
      rt1.push_back(i);
    }
    if (find2(i) == i && check2(1, i)) {
      rt2.push_back(i);
    }
  }
  for (int i = 0; i < (int)min(rt1.size(), rt2.size()); i++) {
    ans.push_back({rt1[i], rt2[i]});
  }
  cout << ans.size() << endl;
  for (auto it : ans) {
    cout << it.first << ' ' << it.second << endl;
  }
  return 0;
}
