#include <bits/stdc++.h>
using namespace std;
const int MOD = (int)1e9 + 7;
const int INF = (int)1e9;
const long long LINF = (long long)1e18;
const long double PI = acos((long double)-1);
const long double EPS = 1e-9;
const int N = (int)1e5 + 10;
void TimeExecution() {
  cout << "\n\n===>> Time Execution: " << clock() / (double)1000 << " sec(s).";
}
inline long long fpow(long long n, long long k) {
  long long r = 1;
  for (; k; k >>= 1) {
    if (k & 1) r = r * n;
    n = n * n;
  }
  return r;
}
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
long long sqr(long long a) { return a * a; }
long long msqr(long long a) { return ((a % MOD) * (a % MOD)) % MOD; }
long long msub(long long a, long long b) { return ((a - b) % MOD + MOD) % MOD; }
long long madd(long long a, long long b) { return (a + b) % MOD; }
long long mmul(long long a, long long b) {
  return ((a % MOD) * (b % MOD)) % MOD;
}
int p1[N];
int s1[N];
int p2[N];
int s2[N];
vector<pair<long long, long long> > ans;
int find_set(int v, int parent[]) {
  if (v == parent[v]) return v;
  return parent[v] = find_set(parent[v], parent);
}
void make_sets(int v, int parent[], int s[]) {
  parent[v] = v;
  s[v] = 1;
}
void union_sets(int a, int b, int parent[], int s[]) {
  a = find_set(a, parent);
  b = find_set(b, parent);
  if (a != b) {
    if (s[a] < s[b]) swap(a, b);
    parent[b] = a;
    s[a] += s[b];
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n, m1, m2;
  cin >> n >> m1 >> m2;
  vector<long long> st1[n + 1];
  vector<long long> st2[n + 1];
  for (int i = (1); i <= (n); i++) {
    make_sets(i, p1, s1);
    make_sets(i, p2, s2);
  }
  for (int i = (1); i <= (m1); i++) {
    int u, v;
    cin >> u >> v;
    union_sets(u, v, p1, s1);
  }
  for (int i = (1); i <= (m2); i++) {
    int u, v;
    cin >> u >> v;
    union_sets(u, v, p2, s2);
  }
  if (max(m1, m2) == n - 1) {
    cout << 0;
    return 0;
  }
  int need = n - 1 - max(m1, m2);
  for (int i = (1); i <= (1); i++) {
    for (int j = (2); j <= (n); j++) {
      if (find_set(i, p1) != find_set(j, p1) &&
          find_set(i, p2) != find_set(j, p2)) {
        union_sets(i, j, p1, s1);
        union_sets(i, j, p2, s2);
        ans.push_back({i, j});
      }
    }
  }
  queue<int> s, t;
  for (int i = (2); i <= (n); i++) {
    if (find_set(i, p1) != find_set(1, p1)) s.push(i);
    if (find_set(i, p2) != find_set(1, p2)) t.push(i);
  }
  while (!s.empty() && !t.empty()) {
    int i = s.front();
    int j = t.front();
    s.pop();
    t.pop();
    ans.push_back({i, j});
    union_sets(i, j, p1, s1);
    union_sets(i, j, p2, s2);
    while (!s.empty() && find_set(s.front(), p1) == find_set(i, p1)) s.pop();
    while (!t.empty() && find_set(t.front(), p2) == find_set(j, p2)) t.pop();
  }
  cout << ans.size() << '\n';
  if (!ans.empty()) {
    for (auto i : ans) {
      cout << i.first << " " << i.second << '\n';
    }
  }
  return 0;
}
