#include <bits/stdc++.h>
using namespace std;
inline int read() {
  int X = 0;
  bool flag = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') flag = 0;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    X = (X << 1) + (X << 3) + ch - '0';
    ch = getchar();
  }
  if (flag) return X;
  return ~(X - 1);
}
const int maxn = 1010;
int t, i, j;
int a[maxn], b[maxn];
int n, m1, m2;
int fa(int x) { return a[x] == x ? x : a[x] = fa(a[x]); }
int fb(int x) { return b[x] == x ? x : b[x] = fb(b[x]); }
void init() {}
vector<pair<int, int> > v;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  t = 1;
  while (t--) {
    cin >> n >> m1 >> m2;
    for (int(i) = (1); (i) <= (n); ++(i)) {
      a[i] = b[i] = i;
    }
    int t1, t2;
    for (int(i) = (1); (i) <= (m1); ++(i)) {
      cin >> t1 >> t2;
      a[fa(t1)] = fa(t2);
    }
    for (int(i) = (1); (i) <= (m2); ++(i)) {
      cin >> t1 >> t2;
      b[fb(t1)] = fb(t2);
    }
    for (int i = 1; i <= n; i++) {
      for (int j = 1; j <= n; j++) {
        int x1 = fa(i);
        int x2 = fa(j);
        int y1 = fb(i);
        int y2 = fb(j);
        if (x1 != x2 && y1 != y2) {
          a[x2] = x1;
          b[y2] = y1;
          v.push_back(make_pair(i, j));
        }
      }
    }
    cout << v.size() << endl;
    int len = v.size() - 1;
    for (int(i) = (0); (i) <= (len); ++(i)) {
      cout << v[i].first << " " << v[i].second << endl;
    }
  }
  return 0;
}
