You are given an array of integers [A1,A2,…,AN]$[A_1, A_2, \ldots, A_N]$. Let's call adding an element to this array at any position (including the beginning and the end) or removing an arbitrary element from it a modification. It is not allowed to remove an element from the array if it is empty.
Find the minimum number of modifications which must be performed so that the resulting array can be partitioned into permutations. Formally, it must be possible to partition elements of the resulting array into zero or more groups (multisets; not necessarily identical) in such a way that each element belongs to exactly one group and for each group, if it contains L$L$ elements, then it must contain only integers 1$1$ through L$L$, each of them exactly once.

-----Input-----
- The first line of the input contains a single integer T$T$ denoting the number of test cases. The description of T$T$ test cases follows.
- The first line of each test case contains a single integer N$N$.
- The second line contains N$N$ space-separated integers A1,A2,…,AN$A_1, A_2, \ldots, A_N$.

-----Output-----
For each test case, print a single line containing one integer ― the minimum required number of modifications.

-----Constraints-----
- 1≤T≤1,000$1 \le T \le 1,000$
- 1≤N≤106$1 \le N \le 10^6$
- 1≤Ai≤109$1 \le A_i \le 10^9$ for each valid i$i$
- the sum of N$N$ over all test cases does not exceed 106$10^6$

-----Subtasks-----
Subtask #1 (50 points):
- 1≤N≤1,000$1 \le N \le 1,000$
- the sum of N$N$ over all test cases does not exceed 10,000$10,000$
Subtask #2 (50 points): original constraints

-----Example Input-----
2
5
1 4 1 2 2
4
2 3 2 3

-----Example Output-----
1
2

```python

USER_FILENAME = "<user_code>"
import sys, json, builtins
import math, heapq, bisect, itertools, functools, collections, statistics, fractions, decimal, operator, array, random, re, string, os, pathlib
try:
    import resource as _res
except Exception:
    _res = None
from collections import Counter, defaultdict, deque, OrderedDict
from functools import lru_cache, reduce
from itertools import accumulate, permutations, combinations, product
from math import gcd, ceil, floor, sqrt
from decimal import Decimal
try:
    from typing import *
except Exception:
    pass
try:
    sys.setrecursionlimit(1_000_000)
except Exception:
    pass
try:
    import site as _site
    try:
        _sys_sites = _site.getsitepackages() if hasattr(_site, "getsitepackages") else []
        for _p in _sys_sites:
            if _p and _p not in sys.path:
                sys.path.append(_p)
    except Exception:
        pass
    try:
        _usp = _site.getusersitepackages()
        if isinstance(_usp, str):
            _usp = [_usp]
        for _p in _usp:
            if _p and _p not in sys.path:
                sys.path.append(_p)
    except Exception:
        pass
except Exception:
    pass

ns = {"__name__": "__main__"}
for _k, _v in list(globals().items()):
    if not _k.startswith("_"):
        ns[_k] = _v
_CODE = '\nfor _ in range(int(input())):\n    n = int(input())\n    a = list(map(int, input().split()))\n    cost = 0\n\n    dp = [[] for val in range(2*n+1)]\n    cnt = [0]*(n*2+1)\n    dp[0].extend([ 0 for val in range(n*2+1) ])\n\n    for val in a:\n     if val<=2*n: cnt[val]+=1\n     else: cost+=1\n \n    for i in range(1, n*2+1):\n     rn = n*2//i\n     for j in range(0, rn+1):\n      dp[i].extend( [ dp[i-1][j] + abs(cnt[i]-j) ] )\n     for j in range(rn-1, -1, -1):\n      dp[i][j] = min(dp[i][j], dp[i][j+1])\n \n    print( cost+min( dp[2*n][0], dp[2*n][1]) )\n\n'
_co = compile(_CODE, USER_FILENAME, "exec")
exec(_co, ns, ns)

```

Measured memory_bytes: 13675