#include <bits/stdc++.h>
using namespace std;
const double PI = acos(-1);
const int INF = INT_MAX;
const long long LLINF = 1000000000000000000LL;
const long long MAX = 1005;
const long long MOD = 1000000007;
long long N, M1, M2;
long long parent[2][MAX], member[2][MAX];
vector<pair<int, int> > ans;
int findRoot(int left, int n) {
  if (parent[left][n] == -1) {
    return n;
  }
  return parent[left][n] = findRoot(left, parent[left][n]);
}
void makeUnion(int left, int r1, int r2) {
  if (r1 != r2) {
    if (member[left][r1] < member[left][r2]) {
      swap(r1, r2);
    }
    parent[left][r2] = r1;
    member[left][r1] += member[left][r2];
  }
}
void solve() {
  cin >> N >> M1 >> M2;
  for (int i = 1; i <= N; i++) {
    parent[0][i] = parent[1][i] = -1;
    member[0][i] = member[1][i] = 1;
  }
  for (int i = 0; i < M1; i++) {
    int a, b;
    cin >> a >> b;
    makeUnion(0, findRoot(0, a), findRoot(0, b));
  }
  for (int i = 0; i < M2; i++) {
    int a, b;
    cin >> a >> b;
    makeUnion(1, findRoot(1, a), findRoot(1, b));
  }
  long long num = 0;
  for (int j = 1; j <= N; j++) {
    for (int i = j + 1; i <= N; i++) {
      if (findRoot(0, j) != findRoot(0, i) &&
          findRoot(1, j) != findRoot(1, i)) {
        ++num;
        pair<int, int> x = make_pair(j, i);
        ans.push_back(x);
        makeUnion(0, findRoot(0, j), findRoot(0, i));
        makeUnion(1, findRoot(1, j), findRoot(1, i));
      }
    }
  }
  cout << num << "\n";
  for (auto it : ans) {
    cout << it.first << " " << it.second << "\n";
  }
}
int main() {
  std::ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  solve();
  return 0;
}
