#include <bits/stdc++.h>
using namespace std;
int b[1007], a[1007];
int p1(int x) { return a[x] == x ? x : a[x] = p1(a[x]); }
int p2(int x) { return b[x] == x ? x : b[x] = p2(b[x]); }
int main() {
  int n, m1, m2;
  scanf("%d%d%d", &n, &m1, &m2);
  for (int i = 1; i <= n; i++) {
    a[i] = b[i] = i;
  }
  for (int i = 1; i <= m1; i++) {
    int u, v;
    scanf("%d%d", &u, &v);
    a[p1(u)] = p1(v);
  }
  for (int i = 1; i <= m2; i++) {
    int u, v;
    scanf("%d%d", &u, &v);
    b[p2(u)] = p2(v);
  }
  vector<pair<int, int> > pii;
  for (int i = 1; i <= n; i++) {
    for (int j = i + 1; j <= n; j++) {
      if (p1(i) != p1(j) && p2(i) != p2(j)) {
        pii.push_back({i, j});
        a[p1(i)] = p1(j);
        b[p2(i)] = p2(j);
      }
    }
  }
  printf("%d\n", pii.size());
  for (int i = 0; i < pii.size(); i++) {
    auto it = pii[i];
    printf("%d %d\n", it.first, it.second);
  }
  printf("\n");
  return 0;
}
