Under construction

Still being built. Things may change

One and Two

Time limit1sMemory limit1024 MB

Summary
Given a sequence of 1s and 2s, find the smallest split point k where the product of the prefix equals the product of the suffix, or report -1.
Level

Easy2 of 10

Topics
Math, Implementation
Solved
No attempts yet

Problem

You are given a sequence a1,a2,…,ana_1, a_2, \ldots, a_n. Each element of aa is 11 or 22.

Find out if an integer kk exists so that the following conditions are met.

  • 1≤k≤n−11 \leq k \leq n-1, and
  • a1⋅a2⋅…⋅ak=ak+1⋅ak+2⋅…⋅ana_1 \cdot a_2 \cdot \ldots \cdot a_k = a_{k+1} \cdot a_{k+2} \cdot \ldots \cdot a_n.

If there exist multiple kk that satisfy the given condition, print the smallest.

Input

Each test contains multiple test cases. The first line contains the number of test cases tt (1≤t≤1001 \le t \le 100). The description of the test cases follows.

The first line of each test case contains one integer nn (2≤n≤10002 \le n \le 1000).

The second line of each test case contains nn integers a1,a2,…,ana_1, a_2, \ldots, a_n (1≤ai≤21 \le a_i \le 2).

Output

For each test case, print the smallest kk that satisfies the conditions. If there is no such kk, print −1-1.

Examples1

  1. Example 1

    Input
    3
    6
    2 2 1 2 1 2
    3
    1 2 1
    4
    1 1 1 1
    
    Expected output
    2
    -1
    1