#include <bits/stdc++.h>
using namespace std;


class Solution{
    public:
    int maxLen(vector<int>&A, int n)
    {   
           // Your code here
        
        unordered_map<int,int> map;
        int maxi =0;
        int sum =0;
        
        for(int i=0; i<n; i++)
        {
            sum+= A[i];
            if(sum == 0)
            {
                maxi = i+1;
            }
            else
            {
                if(map.find(sum)!=map.end())
                {
                    maxi = max(maxi, i-map[sum]);
                    
                }
                else
                {
                    map[sum] =i;
                }
            }
        }
        return maxi;
    
    }
};
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        int m;
        cin>>m;
        vector<int> array1(m);
        for (int i = 0; i < m; ++i){
            cin>>array1[i];
        }
        Solution ob;
        cout<<ob.maxLen(array1,m)<<endl;
    }
    return 0; 
}

//Expected Time Complexity: O(N).
//Expected Auxiliary Space: O(N).
//
