public void solve() throws IOException {
    int n = nextInt();
    List<Integer> s1 = new ArrayList<Integer>(n);
    List<Integer> s2 = new ArrayList<Integer>(n);
    int k1 = nextInt();
    for (int x = 0; x < k1; x++) {
      s1.add(nextInt());
    }
    int k2 = nextInt();
    for (int x = 0; x < k2; x++) {
      s2.add(nextInt());
    }
    
    HashSet<State> seen = new HashSet<State>();
    State cur = new State(s1, s2);
    while (cur.winner() == -1 && !seen.contains(cur)) {
      seen.add(cur);
      cur = cur.move();
    }
    
    if (cur.winner() == -1) {
      System.out.println(-1);
    } else {
      System.out.format("%d %d%n", seen.size(), cur.winner());
    }
  }