description: Paprika loves permutations. She has an array a_1, a_2, ..., a_n. She wants to make the array a permutation of integers 1 to n.
  
  In order to achieve this goal, she can perform operations on the array. In each operation she can choose two integers i (1 ≤ i ≤ n) and x (x > 0), then perform a_i := a_i mod x (that is, replace a_i by the remainder of a_i divided by x). In different operations, the chosen i and x can be different.
  
  Determine the minimum number of operations needed to make the array a permutation of integers 1 to n. If it is impossible, output -1.
  
  A permutation is an array consisting of n distinct integers from 1 to n in arbitrary order. For example, [2,3,1,5,4] is a permutation, but [1,2,2] is not a permutation (2 appears twice in the array) and [1,3,4] is also not a permutation (n=3 but there is 4 in the array).
  
  Input
  
  Each test contains multiple test cases. The first line contains a single integer t (1 ≤ t ≤ 10^4) — the number of test cases. Description of the test cases follows.
  
  The first line of each test case contains an integer n (1 ≤ n ≤ 10^5).
  
  The second line of each test case contains n integers a_1, a_2, ..., a_n. (1 ≤ a_i ≤ 10^9).
  
  It is guaranteed that the sum of n over all test cases does not exceed 2 ⋅ 10^5.
  
  Output
  
  For each test case, output the minimum number of operations needed to make the array a permutation of integers 1 to n, or -1 if it is impossible.
  
  Example
  
  Input
  
  
  4
  2
  1 7
  3
  1 5 4
  4
  12345678 87654321 20211218 23571113
  9
  1 2 3 4 18 19 5 6 7
  
  
  Output
  
  
  1
  -1
  4
  2
  
  Note
  
  For the first test, the only possible sequence of operations which minimizes the number of operations is: 
  
    * Choose i=2, x=5. Perform a_2 := a_2 mod 5 = 2. 
  
  
  
  For the second test, it is impossible to obtain a permutation of integers from 1 to n.
solution: import java.io.BufferedReader;
  import java.io.IOException;
  import java.io.InputStreamReader;
  import java.math.BigInteger;
  import java.text.DecimalFormat;
  import java.util.*;
  import java.util.concurrent.ThreadLocalRandom;
  import java.util.stream.Collectors;
  import java.util.stream.IntStream;
  import java.util.stream.LongStream;
  
  public class B {
  
      static long mod = 1000000007;
      static FastScanner scanner;
  
      static final StringBuilder result = new StringBuilder();
  
      public static void main(String[] args) {
          scanner = new FastScanner();
          int T = scanner.nextInt();
          for (int t = 0; t < T; t++) {
              solve(t + 1);
              result.append("\n");
          }
          System.out.println(result);
      }
  
      static void solve(int t) {
          int n = scanner.nextInt();
          int[] a = scanner.nextIntArray(n);
          ADUtils.sort(a);
          Set<Integer> missing = new LinkedHashSet<>();
          for (int i = 1; i <= n; i++) missing.add(i);
  
          for (int i = 0; i < n; i++) {
              if (a[i] <= n) {
                  missing.remove(a[i]);
              }
          }
  
          List<Integer> missingList = new ArrayList<>(missing);
          int missingIdx = 0;
          Set<Integer> used = new HashSet<>();
          for (int i = 0; i < n; i++) {
              if (a[i] <= n && !used.contains(a[i])) {
                  used.add(a[i]);
                  continue;
              }
              int nextMissing = missingList.get(missingIdx++);
              int x = a[i] - nextMissing;
  
              if (x <= 0 || !((a[i] % x) == nextMissing)) {
                  result.append(-1);
                  return;
              }
          }
          result.append(missingList.size());
      }
  
      static class WithIdx implements Comparable<WithIdx> {
          long val, idx;
  
          public WithIdx(long val, long idx) {
              this.val = val;
              this.idx = idx;
          }
  
          @Override
          public int compareTo(WithIdx o) {
              if (val == o.val) {
                  return Long.compare(idx, o.idx);
              }
              return Long.compare(val, o.val);
          }
      }
  
      public static class FastScanner {
          BufferedReader br;
          StringTokenizer st;
  
          public FastScanner() {
              br = new BufferedReader(new InputStreamReader(System.in));
          }
  
          String nextToken() {
              while (st == null || !st.hasMoreElements()) {
                  try {
                      st = new StringTokenizer(br.readLine());
                  } catch (IOException e) {
                      // TODO Auto-generated catch block
                      e.printStackTrace();
                  }
              }
              return st.nextToken();
          }
  
          String nextLine() {
              try {
                  return br.readLine();
              } catch (Exception e) {
                  e.printStackTrace();
                  throw new RuntimeException();
              }
          }
  
          int nextInt() {
              return Integer.parseInt(nextToken());
          }
  
          long nextLong() {
              return Long.parseLong(nextToken());
          }
  
          double nextDouble() {
              return Double.parseDouble(nextToken());
          }
  
          int[] nextIntArray(int n) {
              int[] res = new int[n];
              for (int i = 0; i < n; i++) res[i] = nextInt();
              return res;
          }
  
          long[] nextLongArray(int n) {
              long[] res = new long[n];
              for (int i = 0; i < n; i++) res[i] = nextLong();
              return res;
          }
  
          String[] nextStringArray(int n) {
              String[] res = new String[n];
              for (int i = 0; i < n; i++) res[i] = nextToken();
              return res;
          }
      }
  
      static class PrefixSums {
          long[] sums;
  
          public PrefixSums(long[] sums) {
              this.sums = sums;
          }
  
          public long sum(int fromInclusive, int toExclusive) {
              if (fromInclusive > toExclusive) throw new IllegalArgumentException("Wrong value");
              return sums[toExclusive] - sums[fromInclusive];
          }
  
          public static PrefixSums of(int[] ar) {
              long[] sums = new long[ar.length + 1];
              for (int i = 1; i <= ar.length; i++) {
                  sums[i] = sums[i - 1] + ar[i - 1];
              }
              return new PrefixSums(sums);
          }
  
          public static PrefixSums of(long[] ar) {
              long[] sums = new long[ar.length + 1];
              for (int i = 1; i <= ar.length; i++) {
                  sums[i] = sums[i - 1] + ar[i - 1];
              }
              return new PrefixSums(sums);
          }
      }
  
      static class ADUtils {
          static void sort(int[] ar) {
              Random rnd = ThreadLocalRandom.current();
              for (int i = ar.length - 1; i > 0; i--) {
                  int index = rnd.nextInt(i + 1);
                  // Simple swap
                  int a = ar[index];
                  ar[index] = ar[i];
                  ar[i] = a;
              }
              Arrays.sort(ar);
          }
  
          static void reverse(int[] arr) {
              int last = arr.length / 2;
              for (int i = 0; i < last; i++) {
                  int tmp = arr[i];
                  arr[i] = arr[arr.length - 1 - i];
                  arr[arr.length - 1 - i] = tmp;
              }
          }
  
          static void sort(long[] ar) {
              Random rnd = ThreadLocalRandom.current();
              for (int i = ar.length - 1; i > 0; i--) {
                  int index = rnd.nextInt(i + 1);
                  // Simple swap
                  long a = ar[index];
                  ar[index] = ar[i];
                  ar[i] = a;
              }
              Arrays.sort(ar);
          }
      }
  
      static class MathUtils {
          static long[] FIRST_PRIMES = {
                  2, 3, 5, 7, 11, 13, 17, 19, 23, 29,
                  31, 37, 41, 43, 47, 53, 59, 61, 67, 71,
                  73, 79, 83, 89, 97, 101, 103, 107, 109, 113,
                  127, 131, 137, 139, 149, 151, 157, 163, 167, 173,
                  179, 181, 191, 193, 197, 199, 211, 223, 227, 229,
                  233, 239, 241, 251, 257, 263, 269, 271, 277, 281,
                  283, 293, 307, 311, 313, 317, 331, 337, 347, 349,
                  353, 359, 367, 373, 379, 383, 389, 397, 401, 409,
                  419, 421, 431, 433, 439, 443, 449, 457, 461, 463,
                  467, 479, 487, 491, 499, 503, 509, 521, 523, 541,
                  547, 557, 563, 569, 571, 577, 587, 593, 599, 601,
                  607, 613, 617, 619, 631, 641, 643, 647, 653, 659,
                  661, 673, 677, 683, 691, 701, 709, 719, 727, 733,
                  739, 743, 751, 757, 761, 769, 773, 787, 797, 809,
                  811, 821, 823, 827, 829, 839, 853, 857, 859, 863,
                  877, 881, 883, 887, 907, 911, 919, 929, 937, 941,
                  947, 953, 967, 971, 977, 983, 991, 997, 1009, 1013,
                  1019, 1021, 1031, 1033, 1039, 1049, 1051};
  
          static long[] primes(int to) {
              long[] all = new long[to + 1];
              long[] primes = new long[to + 1];
              all[1] = 1;
              int primesLength = 0;
              for (int i = 2; i <= to; i++) {
                  if (all[i] == 0) {
                      primes[primesLength++] = i;
                      all[i] = i;
                  }
                  for (int j = 0; j < primesLength && i * primes[j] <= to && all[i] >= primes[j];
                       j++) {
                      all[(int) (i * primes[j])] = primes[j];
                  }
              }
              return Arrays.copyOf(primes, primesLength);
          }
  
          static long modpow(long b, long e, long m) {
              long result = 1;
  
              while (e > 0) {
                  if ((e & 1) == 1) {
                      /* multiply in this bit's contribution while using modulus to keep
                       * result small */
                      result = (result * b) % m;
                  }
                  b = (b * b) % m;
                  e >>= 1;
              }
  
              return result;
          }
  
          static long submod(long x, long y, long m) {
              return (x - y + m) % m;
          }
  
          static long modInverse(long a, long m) {
              long g = gcdF(a, m);
              if (g != 1) {
                  throw new IllegalArgumentException("Inverse doesn't exist");
              } else {
                  // If a and m are relatively prime, then modulo
                  // inverse is a^(m-2) mode m
                  return modpow(a, m - 2, m);
              }
          }
  
          static public long gcdF(long a, long b) {
              while (b != 0) {
                  long na = b;
                  long nb = a % b;
                  a = na;
                  b = nb;
              }
              return a;
          }
      }
  }