description: This is the easy version of the problem. The only difference between the two versions is the constraint on n. You can make hacks only if all versions of the problem are solved.
  
  A forest is an undirected graph without cycles (not necessarily connected).
  
  Mocha and Diana are friends in Zhijiang, both of them have a forest with nodes numbered from 1 to n, and they would like to add edges to their forests such that: 
  
    * After adding edges, both of their graphs are still forests. 
    * They add the same edges. That is, if an edge (u, v) is added to Mocha's forest, then an edge (u, v) is added to Diana's forest, and vice versa. 
  
  
  
  Mocha and Diana want to know the maximum number of edges they can add, and which edges to add.
  
  Input
  
  The first line contains three integers n, m_1 and m_2 (1 ≤ n ≤ 1000, 0 ≤ m_1, m_2 < n) — the number of nodes and the number of initial edges in Mocha's forest and Diana's forest.
  
  Each of the next m_1 lines contains two integers u and v (1 ≤ u, v ≤ n, u ≠ v) — the edges in Mocha's forest.
  
  Each of the next m_2 lines contains two integers u and v (1 ≤ u, v ≤ n, u ≠ v) — the edges in Diana's forest.
  
  Output
  
  The first line contains only one integer h, the maximum number of edges Mocha and Diana can add (in each forest).
  
  Each of the next h lines contains two integers u and v (1 ≤ u, v ≤ n, u ≠ v) — the edge you add each time.
  
  If there are multiple correct answers, you can print any one of them.
  
  Examples
  
  Input
  
  
  3 2 2
  1 2
  2 3
  1 2
  1 3
  
  
  Output
  
  
  0
  
  
  Input
  
  
  5 3 2
  5 4
  2 1
  4 3
  4 3
  1 4
  
  
  Output
  
  
  1
  2 4
  
  
  Input
  
  
  8 1 2
  1 7
  2 6
  1 5
  
  
  Output
  
  
  5
  5 2
  2 3
  3 4
  4 7
  6 8
  
  Note
  
  In the first example, we cannot add any edge.
  
  In the second example, the initial forests are as follows.
  
  <image>
  
  We can add an edge (2, 4).
  
  <image>
solution: import java.util.*;
  import java.io.*;
  
  public class _1559D1 {
      static int[] MODS = {1000000007, 998244353, 1000000009};
      static int MOD = MODS[0];
      static long[] fact, inv;
  
      public static void main(String[] args) {
          sc = new MyScanner();
          out = new PrintWriter(new BufferedOutputStream(System.out));
          int n = sc.nextInt();
          int m1 = sc.nextInt();
          int m2 = sc.nextInt();
          UnionFind mocha = new UnionFind(n+1);
          UnionFind diana = new UnionFind(n+1);
          int[][] mochaEdges = new int[m1][2];
          for (int i = 0; i < m1; i++) {
              mochaEdges[i][0] = sc.nextInt();
              mochaEdges[i][1] = sc.nextInt();
              mocha.connect(mochaEdges[i][0], mochaEdges[i][1]);
          }
          int[][] dianaEdges = new int[m2][2];
          for (int i = 0; i < m2; i++) {
              dianaEdges[i][0] = sc.nextInt();
              dianaEdges[i][1] = sc.nextInt();
              diana.connect(dianaEdges[i][0], dianaEdges[i][1]);
          }
          ArrayList<int[]> list = new ArrayList<>();
          for (int i = 1; i <= n; i++) {
              for (int j = 1; j <= n; j++) {
                  if (!mocha.isConnected(i, j) && !diana.isConnected(i, j)) {
                      mocha.connect(i, j);
                      diana.connect(i, j);
                      list.add(new int[]{i, j});
                  }
              }
          }
          out.println(list.size());
          for (int[] arr : list) {
              out.println(arr[0] + " " + arr[1]);
          }
          out.close();
      }
  
      public static void printArray(int[] arr) {
          for (int x : arr) {
              out.print(x + " ");
          }
          out.println();
      }
  
      public static long pow(long base, int power) {
          if (power == 0) {
              return 1;
          }
          long sqrt = pow(base, power / 2);
          sqrt = (sqrt * sqrt) % MOD;
          if (power % 2 == 1) {
              sqrt = (sqrt * base) % MOD;
          }
          return sqrt;
      }
  
      public static long inverse(long x) {
          return pow(x, MOD - 2);
      }
  
      public static long choose(int n, int k) {
          long ans = 1;
          for (int i = 0; i < k; i++) {
              ans = ans * (n - i);
          }
          for (int i = 1; i <= k; i++) {
              ans /= i;
          }
          return ans;
      }
  
      public static void precomputeFactorial(int n) {
          fact = new long[n + 1];
          inv = new long[n + 1];
          fact[0] = 1;
          inv[0] = 1;
          for (int i = 1; i <= n; i++) {
              fact[i] = (fact[i - 1] * i) % MOD;
              inv[i] = inverse(fact[i]);
          }
      }
  
      public static long[] sort(long[] arr) {
          ArrayList<Long> list = new ArrayList<>();
          for (long x : arr) {
              list.add(x);
          }
          Collections.sort(list);
          for (int i = 0; i < arr.length; i++) {
              arr[i] = list.get(i);
          }
          return arr;
      }
  
      public static int[] sort(int[] arr) {
          ArrayList<Integer> list = new ArrayList<>();
          for (int x : arr) {
              list.add(x);
          }
          Collections.sort(list);
          for (int i = 0; i < arr.length; i++) {
              arr[i] = list.get(i);
          }
          return arr;
      }
  
      public static void scan(long[] arr) {
          for (int i = 0; i < arr.length; i++) {
              arr[i] = sc.nextLong();
          }
      }
  
      public static void scan(int[] arr) {
          for (int i = 0; i < arr.length; i++) {
              arr[i] = sc.nextInt();
          }
      }
  
      public static long[] scanLong(int n) {
          long[] arr = new long[n];
          for (int i = 0; i < arr.length; i++) {
              arr[i] = sc.nextLong();
          }
          return arr;
      }
  
      public static int[] scan(int n) {
          int[] arr = new int[n];
          for (int i = 0; i < arr.length; i++) {
              arr[i] = sc.nextInt();
          }
          return arr;
      }
  
      public static MyScanner sc;
      public static PrintWriter out;
  
      public static class MyScanner {
          BufferedReader br;
          StringTokenizer st;
  
          public MyScanner() {
              br = new BufferedReader(new InputStreamReader(System.in));
          }
  
          String next() {
              while (st == null || !st.hasMoreElements()) {
                  try {
                      st = new StringTokenizer(br.readLine());
                  } catch (IOException e) {
                      e.printStackTrace();
                  }
              }
              return st.nextToken();
          }
  
          int nextInt() {
              return Integer.parseInt(next());
          }
  
          long nextLong() {
              return Long.parseLong(next());
          }
  
          double nextDouble() {
              return Double.parseDouble(next());
          }
  
          String nextLine() {
              String str = "";
              try {
                  str = br.readLine();
              } catch (IOException e) {
                  e.printStackTrace();
              }
              return str;
          }
      }
  
      public static class UnionFind {
          int[] parent;
  
          public UnionFind(int n) {
              parent = new int[n];
              for (int i = 0; i < n; i++) {
                  parent[i] = -1;
              }
          }
  
          public int sizeOf(int v1) {
              int root = find(v1);
              return -1 * parent[root];
          }
  
          public int parent(int v1) {
              return parent[v1];
          }
  
          public boolean isConnected(int v1, int v2) {
              return find(v1) == find(v2);
          }
  
          public void connect(int v1, int v2) {
              if (isConnected(v1, v2)) {
                  return;
              }
              int par1 = find(v1);
              int par2 = find(v2);
              if (parent[par1] < parent[par2]) {
                  parent[par1] += parent[par2];
                  parent[par2] = par1;
              } else {
                  parent[par2] += parent[par1];
                  parent[par1] = par2;
              }
          }
  
          public int find(int v1) {
              if (parent[v1] < 0) {
                  return v1;
              }
              return parent[v1] = find(parent[v1]);
          }
  
      }
  }
  