#include <bits/stdc++.h>
using namespace std;
const int N = 100000 + 10;
int vis1[N], vis2[N];
vector<int> g1[N], g2[N];
set<int> s;
void dfs2(int u, int p) {
  if (vis2[u]) return;
  s.insert(p);
  vis2[u] = p;
  for (int v : g2[u])
    if (!vis2[v]) dfs2(v, p);
}
void dfs1(int u) {
  vis1[u] = 1;
  dfs2(u, u);
  for (int v : g1[u])
    if (!vis1[v]) dfs1(v);
}
int par[N];
int find(int x) {
  if (x == par[x]) return x;
  return par[x] = find(par[x]);
}
int main() {
  ios::sync_with_stdio(0);
  int n, m1, m2;
  cin >> n >> m1 >> m2;
  for (int i = 1; i <= n; i++) par[i] = i;
  while (m1--) {
    int u, v;
    cin >> u >> v;
    g1[u].push_back(v);
    g1[v].push_back(u);
  }
  while (m2--) {
    int u, v;
    cin >> u >> v;
    g2[u].push_back(v);
    g2[v].push_back(u);
  }
  dfs1(1);
  vector<array<int, 2>> e;
  for (int t = 0; t < 2; t++) {
    for (int i = 1; i <= n; i++)
      if (!vis1[i]) {
        if (!vis2[i]) dfs2(i, i);
        if (s.size() == 1) continue;
        s.erase(find(vis2[i]));
        e.push_back({find(*s.begin()), i});
        par[find(vis2[i])] = find(*s.begin());
        dfs1(i);
      }
  }
  cout << e.size() << endl;
  for (auto [u, v] : e) {
    cout << u << ' ' << v << endl;
  }
}
