Problem: You are given a sequence a_1, a_2, …, a_n of non-negative integers.

You need to find the largest number m of triples (i_1, j_1, k_1), (i_2, j_2, k_2), ..., (i_m, j_m, k_m) such that:

  * 1 ≤ i_p < j_p < k_p ≤ n for each p in 1, 2, …, m;
  * a_{i_p} = a_{k_p} = 0, a_{j_p} ≠ 0;
  * all a_{j_1}, a_{j_2}, …, a_{j_m} are different;
  * all i_1, j_1, k_1, i_2, j_2, k_2, …, i_m, j_m, k_m are different.

Input

The first line of input contains one integer t (1 ≤ t ≤ 500 000): the number of test cases.

The first line of each test case contains one integer n (1 ≤ n ≤ 500 000).

The second line contains n integers a_1, a_2, …, a_n (0 ≤ a_i ≤ n).

The total sum of n is at most 500 000.

Output

For each test case, print one integer m: the largest number of proper triples that you can find.

Example

Input


8
1
1
2
0 0
3
0 1 0
6
0 0 1 2 0 0
6
0 1 0 0 1 0
6
0 1 3 2 0 0
6
0 0 0 0 5 0
12
0 1 0 2 2 2 0 0 3 3 4 0


Output


0
0
1
2
1
1
1
2

Note

In the first two test cases, there are not enough elements even for a single triple, so the answer is 0.

In the third test case we can select one triple (1, 2, 3).

In the fourth test case we can select two triples (1, 3, 5) and (2, 4, 6).

In the fifth test case we can select one triple (1, 2, 3). We can't select two triples (1, 2, 3) and (4, 5, 6), because a_2 = a_5.

Solution (in JAVA):

Solution:
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.PriorityQueue;
import java.util.AbstractQueue;
import java.util.HashMap;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.AbstractCollection;
import java.util.Map;
import java.util.Comparator;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) throws Exception {
        Thread thread = new Thread(null, new TaskAdapter(), "", 1 << 29);
        thread.start();
        thread.join();
    }

    static class TaskAdapter implements Runnable {
        @Override
        public void run() {
            InputStream inputStream = System.in;
            OutputStream outputStream = System.out;
            FastInput in = new FastInput(inputStream);
            PrintWriter out = new PrintWriter(outputStream);
            HRainbowTriples solver = new HRainbowTriples();
            int testCount = Integer.parseInt(in.next());
            for (int i = 1; i <= testCount; i++)
                solver.solve(i, in, out);
            out.close();
        }
    }

    static class HRainbowTriples {
        int n;

        public int[] newInterval() {
            return new int[]{-1, n + 1};
        }

        public void updateL(int[] lr, int l) {
            lr[0] = Math.max(lr[0], l);
        }

        public void updateR(int[] lr, int r) {
            lr[1] = Math.min(lr[1], r);
        }

        public void solve(int testNumber, FastInput in, PrintWriter out) {
            n = in.readInt();
            int[] a = new int[n];
            in.populate(a);
            IntegerPreSum ips = new IntegerPreSum(i -> a[i] == 0 ? 1 : 0,
                    n);
            int cnt = ips.prefix(n);
            int half = cnt / 2;
            if (cnt < 2) {
                out.println(0);
                return;
            }

            Map<Integer, int[]> map = new HashMap<>();
            for (int i = 0; i < n; i++) {
                if (a[i] == 0) {
                    continue;
                }
                int[] range = map.get(a[i]);
                if (range == null) {
                    range = newInterval();
                    map.put(a[i], range);
                }
                if (ips.prefix(i) >= half) {
                    updateR(range, i);
                }
                if (ips.post(i) >= half) {
                    updateL(range, i);
                }
            }

            List<int[]> list = new ArrayList<>(map.values());
            list.sort(Comparator.comparingInt(x -> x[0]));
            int head = 0;

            List<int[]> right = new ArrayList<>(n);
            PriorityQueue<int[]> added = new PriorityQueue<>(n,
                    (x, y) -> Integer.compare(x[1], y[1]));
            for (int i = -1; i <= n + 1; i++) {
                int size = Math.min(half, ips.prefix(i));
                while (added.size() < size && head < list.size()) {
                    added.add(list.get(head++));
                }
                while (head < list.size() && list.get(head)[0] == i) {
                    int[] top = list.get(head++);
                    if (!added.isEmpty() && added.peek()[1] < top[1]) {
                        right.add(added.remove());
                        added.add(top);
                    } else {
                        right.add(top);
                    }
                }
            }

            right.sort((x, y) -> -Integer.compare(x[1], y[1]));
            int curSize = 0;
            head = 0;
            for (int i = n + 1; i >= -1; i--) {
                int size = Math.min(half, ips.post(i));
                while (curSize < size && head < right.size()) {
                    head++;
                    curSize++;
                }
                while (head < right.size() && right.get(head)[1] == i) {
                    head++;
                }
            }

            int ans = curSize + added.size();
            ans = Math.min(ans, half);
            out.println(ans);
        }

    }

    static class FastInput {
        private final InputStream is;
        private StringBuilder defaultStringBuf = new StringBuilder(1 << 13);
        private byte[] buf = new byte[1 << 13];
        private int bufLen;
        private int bufOffset;
        private int next;

        public FastInput(InputStream is) {
            this.is = is;
        }

        public void populate(int[] data) {
            for (int i = 0; i < data.length; i++) {
                data[i] = readInt();
            }
        }

        private int read() {
            while (bufLen == bufOffset) {
                bufOffset = 0;
                try {
                    bufLen = is.read(buf);
                } catch (IOException e) {
                    bufLen = -1;
                }
                if (bufLen == -1) {
                    return -1;
                }
            }
            return buf[bufOffset++];
        }

        public void skipBlank() {
            while (next >= 0 && next <= 32) {
                next = read();
            }
        }

        public String next() {
            return readString();
        }

        public int readInt() {
            int sign = 1;

            skipBlank();
            if (next == '+' || next == '-') {
                sign = next == '+' ? 1 : -1;
                next = read();
            }

            int val = 0;
            if (sign == 1) {
                while (next >= '0' && next <= '9') {
                    val = val * 10 + next - '0';
                    next = read();
                }
            } else {
                while (next >= '0' && next <= '9') {
                    val = val * 10 - next + '0';
                    next = read();
                }
            }

            return val;
        }

        public String readString(StringBuilder builder) {
            skipBlank();

            while (next > 32) {
                builder.append((char) next);
                next = read();
            }

            return builder.toString();
        }

        public String readString() {
            defaultStringBuf.setLength(0);
            return readString(defaultStringBuf);
        }

    }

    static interface IntToIntegerFunction {
        int apply(int x);

    }

    static class IntegerPreSum {
        private int[] pre;
        private int n;

        public IntegerPreSum(int n) {
            pre = new int[n];
        }

        public void populate(IntToIntegerFunction a, int n) {
            this.n = n;
            if (n == 0) {
                return;
            }
            pre[0] = a.apply(0);
            for (int i = 1; i < n; i++) {
                pre[i] = pre[i - 1] + a.apply(i);
            }
        }

        public IntegerPreSum(IntToIntegerFunction a, int n) {
            this(n);
            populate(a, n);
        }

        public int prefix(int i) {
            i = Math.min(i, n - 1);
            if (i < 0) {
                return 0;
            }
            return pre[i];
        }

        public int post(int i) {
            return prefix(n) - prefix(i - 1);
        }

    }
}