import java.io.*;
import java.lang.reflect.Array;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.math.RoundingMode;
import java.text.DecimalFormat;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Main
{
   static long mod=(long)(1e+9 + 7);
   //static long mod=(long)998244353;

   static int[] sieve;
   static ArrayList<Integer> primes;
   static PrintWriter out;
   static fast s;
   static StringBuilder fans;

   public static void solve()
   {
   	int n=s.nextInt();
   	int a[]=new int[n];
   	for(int i=0;i<n;i++) a[i]=s.nextInt();

   	int ans=1;

   	int left[]=new int[201];
   	int right[]=new int[201];

   	Arrays.fill(left, Integer.MAX_VALUE);
   	Arrays.fill(right, -1);

   	for(int i=0;i<n;i++) left[a[i]]=Math.min(left[a[i]], i);
   	for(int i=0;i<n;i++) right[a[i]]=Math.max(right[a[i]], i);

   	int f[][]=new int[n][201];
   	int next[][]=new int[n][201];
   	int prev[][]=new int[n][201];
   	int temp[]=new int[201];

   	f[0][a[0]]++;

   	for(int i=1;i<n;i++)
   		{
   			for(int k=1;k<=200;k++) f[i][k]=f[i-1][k];
   			f[i][a[i]]++;
   		}

   	Arrays.fill(temp, -1);
   	for(int i=0;i<n;i++)
   		{
   		   for(int k=1;k<=200;k++)
                prev[i][k]=temp[k];
   	   	temp[a[i]]=i;
   		}

   	Arrays.fill(temp, n+2);
   	for(int i=n-1;i>=0;i--)
   		{
   		   for(int k=1;k<=200;k++)
                next[i][k]=temp[k];
   	   	temp[a[i]]=i;
   		}

   	for(int k=1;k<=200;k++)
   		{
   			int l=left[k];
   			int r=right[k];

   			if(l==r || l==Integer.MAX_VALUE) continue;
   			if(r==l+1) {ans=Math.max(ans, 2);continue;}

   			int i=l;
   			int j=r;
   			int cnt=2;

   			while(i<j)
   				{
   					if(a[i]==a[j] && a[i]==k)
   						{
		   					int cur=cnt;
		   					int maxi=0;

		   					for(int p=1;p<=200;p++)
		   						{
		   							int pp=f[j-1][p]-f[i][p];
		   							maxi=Math.max(maxi, pp);
		   						}
		   					ans=Math.max(ans, cur+maxi);
		   					cnt+=2;
		   					i=next[i][k];
		   					j=prev[j][k];
   						}
   					else
   						{
   							if(a[i]!=k) i=next[i][k];
   							if(a[j]!=k) j=prev[j][k];
   						}
   				}
   		}
   	fans.append(ans+"\n");
   }

   public static void main(String[] args) throws java.lang.Exception
   {
	     s = new fast();
	     out=new PrintWriter(System.out);
	     fans=new StringBuilder("");

	     int t=s.nextInt();

	     while(t>0)
	    	 {
	    		 solve();
	    		 t--;
	    	 }

	    out.println(fans);
	    out.close();
   }

static class fast {

	   private InputStream i;
		private byte[]  buf = new byte[1024];
		private int curChar;

		private int numChars;

		//Return floor log2n
		public static long log2(long bits) // returns 0 for bits=0
			{
			    int log = 0;
			    if( ( bits & 0xffff0000 ) != 0 ) { bits >>>= 16; log = 16; }
			    if( bits >= 256 ) { bits >>>= 8; log += 8; }
			    if( bits >= 16  ) { bits >>>= 4; log += 4; }
			    if( bits >= 4   ) { bits >>>= 2; log += 2; }
			    return log + ( bits >>> 1 );
			}

		public static boolean next_permutation(int a[])
		   {
			   int i=0,j=0;int index=-1;
			   int n=a.length;

			   for(i=0;i<n-1;i++)
				   if(a[i]<a[i+1]) index=i;

			   if(index==-1) return false;
			   i=index;

			   for(j=i+1;j<n && a[i]<a[j];j++);

			   int temp=a[i];
			   a[i]=a[j-1];
			   a[j-1]=temp;

			   for(int p=i+1,q=n-1;p<q;p++,q--)
			   {
				   temp=a[p];
				   a[p]=a[q];
				   a[q]=temp;
			   }

			   return true;
		   }

		public static void division(char ch[],int divisor)
		   {
			   int div=Character.getNumericValue(ch[0]); int mul=10;int remainder=0;
			   StringBuilder quotient=new StringBuilder("");
			   for(int i=1;i<ch.length;i++)
			   {
				   div=div*mul+Character.getNumericValue(ch[i]);
				   if(div<divisor) {quotient.append("0");continue;}
				   quotient.append(div/divisor);
				   div=div%divisor;mul=10;

			   }
			   remainder=div;
			   while(quotient.charAt(0)=='0')quotient.deleteCharAt(0);
			   System.out.println(quotient+" "+remainder);
		   }

		public static void sieve(int size)
		{
			sieve=new int[size+1];

			primes=new ArrayList<Integer>();

			sieve[1]=1;

			for(int i=2;i*i<=size;i++)
			{
				if(sieve[i]==0)
				 {
					for(int j=i*i;j<size;j+=i) {sieve[j]=1;}
				 }
			}

			for(int i=2;i<=size;i++)
			{
				if(sieve[i]==0) primes.add(i);
			}
		}

		public static long pow(long n, long b, long MOD)
		   {
		       long x=1;long y=n;
		       while(b > 0)
		       {
		           if(b%2 == 1)
		           {
		               x=x*y;
		               if(x>MOD) x=x%(MOD);
		           }
		           y = y*y;
		           if(y>MOD) y=y%(MOD);
		           b >>= 1;
		       }
		       return x;
		   }

		public static long mod_inv(long n,long mod)
		{
			return pow(n,mod-2,mod);
		}

		//Returns index of highest number less than or equal to key
		 public static int upper(long[] a,int length,long key)
		 {
			    int low = 0;
		        int high = length-1;
		        int ans=-1;

		        while (low <= high) {
		            int mid = (low + high) / 2;
		            if (key >= a[mid]) {
		                ans=mid;
		            	low = mid+1;
		            } else if(a[mid]>key){
		                high = mid - 1;
		            }
		        }
		        return ans;
		}

		//Returns index of least number greater than or equal to key
		 public static int lower(long[] a,int length,long key)
		 {
			    int low = 0;
		        int high = length-1;
		        int ans=-1;

		        while (low <= high) {
		            int mid = (low + high) / 2;
		            if (key<=a[mid]) {
		                ans=mid;
		            	high = mid-1;
		            }
		            else{
		            		low=mid+1;
		            	}
		        }
		        return ans;
		}

		public long gcd(long r,long ans)
		{
			if(r==0) return ans;
			return gcd(ans%r,r);
		}
		public fast() {
			this(System.in);
		}
		public fast(InputStream is) {
			i = is;
		}
		public int read() {
			if (numChars == -1)
				throw new InputMismatchException();
			if (curChar >= numChars) {
				curChar = 0;
				try {
					numChars = i.read(buf);
				} catch (IOException e) {
					throw new InputMismatchException();
				}
				if (numChars <= 0)
					return -1;
			}
			return buf[curChar++];
		}
		public String nextLine() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			StringBuilder res = new StringBuilder();
			do {
				res.appendCodePoint(c);
				c = read();
			} while (!isEndOfLine(c));
			return res.toString();
		}
		public String nextString() {
     		int c = read();
			while (isSpaceChar(c))
				c = read();
			StringBuilder res = new StringBuilder();
			do {
				res.appendCodePoint(c);
				c = read();
			} while (!isSpaceChar(c));
			return res.toString();
		}
		public long nextLong() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			int sgn = 1;
			if (c == '-') {
				sgn = -1;
				c = read();
			}
			long res = 0;
			do {
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res *= 10;
				res += c - '0';
				c = read();
			} while (!isSpaceChar(c));
			return res * sgn;
		}
		public int nextInt() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			int sgn = 1;
			if (c == '-') {
				sgn = -1;
				c = read();
			}
			int res = 0;
			do {
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res *= 10;
				res += c - '0';
				c = read();
			} while (!isSpaceChar(c));
			return res * sgn;
		}
		public boolean isSpaceChar(int c) {
			return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
		}
		public boolean isEndOfLine(int c) {
			return c == '\n' || c == '\r' || c == -1;
		}

	}
}


import java.io.*;
import java.lang.reflect.Array;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.math.RoundingMode;
import java.text.DecimalFormat;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Main
{
   static long mod=(long)(1e+9 + 7);
   //static long mod=(long)998244353;

   static int[] sieve;
   static ArrayList<Integer> primes;
   static PrintWriter out;
   static fast s;
   static StringBuilder fans;

   public static void solve()
   {
   	int n=s.nextInt();
   	int a[]=new int[n];
   	for(int i=0;i<n;i++) a[i]=s.nextInt();

   	int ans=1;

   	int left[]=new int[201];
   	int right[]=new int[201];

   	Arrays.fill(left, Integer.MAX_VALUE);
   	Arrays.fill(right, -1);

   	for(int i=0;i<n;i++) left[a[i]]=Math.min(left[a[i]], i);
   	for(int i=0;i<n;i++) right[a[i]]=Math.max(right[a[i]], i);

   	int f[][]=new int[n][201];
   	f[0][a[0]]++;

   	for(int i=1;i<n;i++)
   		{
   			for(int k=1;k<=200;k++) f[i][k]=f[i-1][k];
   			f[i][a[i]]++;
   		}

   	for(int k=1;k<=26;k++)
   		{
   			int l=left[k];
   			int r=right[k];

   			if(l==r || l==Integer.MAX_VALUE) continue;
   			if(r==l+1) {ans=Math.max(ans, 2);continue;}

   			int i=l;
   			int j=r;
   			int cnt=2;

   			while(i<j)
   				{
   					if(a[i]==a[j] && a[i]==k)
   						{
		   					int cur=cnt;
		   					int maxi=0;

		   					for(int p=1;p<=26;p++)
		   						{
		   							int pp=f[j-1][p]-f[i][p];
		   							maxi=Math.max(maxi, pp);
		   						}
		   					ans=Math.max(ans, cur+maxi);
		   					cnt+=2;
		   					i++;
		   					j--;
   						}
   					else
   						{
   							if(a[i]!=k) i++;
   							if(a[j]!=k) j--;
   						}
   				}
   		}
   	fans.append(ans+"\n");
   }

   public static void main(String[] args) throws java.lang.Exception
   {
	     s = new fast();
	     out=new PrintWriter(System.out);
	     fans=new StringBuilder("");

	     int t=s.nextInt();

	     while(t>0)
	    	 {
	    		 solve();
	    		 t--;
	    	 }

	    out.println(fans);
	    out.close();
   }

static class fast {

	   private InputStream i;
		private byte[]  buf = new byte[1024];
		private int curChar;

		private int numChars;

		//Return floor log2n
		public static long log2(long bits) // returns 0 for bits=0
			{
			    int log = 0;
			    if( ( bits & 0xffff0000 ) != 0 ) { bits >>>= 16; log = 16; }
			    if( bits >= 256 ) { bits >>>= 8; log += 8; }
			    if( bits >= 16  ) { bits >>>= 4; log += 4; }
			    if( bits >= 4   ) { bits >>>= 2; log += 2; }
			    return log + ( bits >>> 1 );
			}

		public static boolean next_permutation(int a[])
		   {
			   int i=0,j=0;int index=-1;
			   int n=a.length;

			   for(i=0;i<n-1;i++)
				   if(a[i]<a[i+1]) index=i;

			   if(index==-1) return false;
			   i=index;

			   for(j=i+1;j<n && a[i]<a[j];j++);

			   int temp=a[i];
			   a[i]=a[j-1];
			   a[j-1]=temp;

			   for(int p=i+1,q=n-1;p<q;p++,q--)
			   {
				   temp=a[p];
				   a[p]=a[q];
				   a[q]=temp;
			   }

			   return true;
		   }

		public static void division(char ch[],int divisor)
		   {
			   int div=Character.getNumericValue(ch[0]); int mul=10;int remainder=0;
			   StringBuilder quotient=new StringBuilder("");
			   for(int i=1;i<ch.length;i++)
			   {
				   div=div*mul+Character.getNumericValue(ch[i]);
				   if(div<divisor) {quotient.append("0");continue;}
				   quotient.append(div/divisor);
				   div=div%divisor;mul=10;

			   }
			   remainder=div;
			   while(quotient.charAt(0)=='0')quotient.deleteCharAt(0);
			   System.out.println(quotient+" "+remainder);
		   }

		public static void sieve(int size)
		{
			sieve=new int[size+1];

			primes=new ArrayList<Integer>();

			sieve[1]=1;

			for(int i=2;i*i<=size;i++)
			{
				if(sieve[i]==0)
				 {
					for(int j=i*i;j<size;j+=i) {sieve[j]=1;}
				 }
			}

			for(int i=2;i<=size;i++)
			{
				if(sieve[i]==0) primes.add(i);
			}
		}

		public static long pow(long n, long b, long MOD)
		   {
		       long x=1;long y=n;
		       while(b > 0)
		       {
		           if(b%2 == 1)
		           {
		               x=x*y;
		               if(x>MOD) x=x%(MOD);
		           }
		           y = y*y;
		           if(y>MOD) y=y%(MOD);
		           b >>= 1;
		       }
		       return x;
		   }

		public static long mod_inv(long n,long mod)
		{
			return pow(n,mod-2,mod);
		}

		//Returns index of highest number less than or equal to key
		 public static int upper(long[] a,int length,long key)
		 {
			    int low = 0;
		        int high = length-1;
		        int ans=-1;

		        while (low <= high) {
		            int mid = (low + high) / 2;
		            if (key >= a[mid]) {
		                ans=mid;
		            	low = mid+1;
		            } else if(a[mid]>key){
		                high = mid - 1;
		            }
		        }
		        return ans;
		}

		//Returns index of least number greater than or equal to key
		 public static int lower(long[] a,int length,long key)
		 {
			    int low = 0;
		        int high = length-1;
		        int ans=-1;

		        while (low <= high) {
		            int mid = (low + high) / 2;
		            if (key<=a[mid]) {
		                ans=mid;
		            	high = mid-1;
		            }
		            else{
		            		low=mid+1;
		            	}
		        }
		        return ans;
		}

		public long gcd(long r,long ans)
		{
			if(r==0) return ans;
			return gcd(ans%r,r);
		}
		public fast() {
			this(System.in);
		}
		public fast(InputStream is) {
			i = is;
		}
		public int read() {
			if (numChars == -1)
				throw new InputMismatchException();
			if (curChar >= numChars) {
				curChar = 0;
				try {
					numChars = i.read(buf);
				} catch (IOException e) {
					throw new InputMismatchException();
				}
				if (numChars <= 0)
					return -1;
			}
			return buf[curChar++];
		}
		public String nextLine() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			StringBuilder res = new StringBuilder();
			do {
				res.appendCodePoint(c);
				c = read();
			} while (!isEndOfLine(c));
			return res.toString();
		}
		public String nextString() {
     		int c = read();
			while (isSpaceChar(c))
				c = read();
			StringBuilder res = new StringBuilder();
			do {
				res.appendCodePoint(c);
				c = read();
			} while (!isSpaceChar(c));
			return res.toString();
		}
		public long nextLong() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			int sgn = 1;
			if (c == '-') {
				sgn = -1;
				c = read();
			}
			long res = 0;
			do {
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res *= 10;
				res += c - '0';
				c = read();
			} while (!isSpaceChar(c));
			return res * sgn;
		}
		public int nextInt() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			int sgn = 1;
			if (c == '-') {
				sgn = -1;
				c = read();
			}
			int res = 0;
			do {
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res *= 10;
				res += c - '0';
				c = read();
			} while (!isSpaceChar(c));
			return res * sgn;
		}
		public boolean isSpaceChar(int c) {
			return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
		}
		public boolean isEndOfLine(int c) {
			return c == '\n' || c == '\r' || c == -1;
		}

	}
}


import java.io.*;
import java.lang.reflect.Array;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.math.RoundingMode;
import java.text.DecimalFormat;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Main
{
   static long mod=(long)(1e+9 + 7);
   //static long mod=(long)998244353;

   static int[] sieve;
   static ArrayList<Integer> primes;
   static PrintWriter out;
   static fast s;
   static StringBuilder fans;

   public static void solve()
   {
   	int n=s.nextInt();
   	int a[]=new int[n];
   	for(int i=0;i<n;i++) a[i]=s.nextInt();

   	int ans=1;

   	int left[]=new int[201];
   	int right[]=new int[201];

   	Arrays.fill(left, Integer.MAX_VALUE);
   	Arrays.fill(right, -1);

   	for(int i=0;i<n;i++) left[a[i]]=Math.min(left[a[i]], i);
   	for(int i=0;i<n;i++) right[a[i]]=Math.max(right[a[i]], i);

   	int f[][]=new int[n][201];

   	ArrayList<Integer> next[]=new ArrayList[201];
   	ArrayList<Integer> prev[]=new ArrayList[201];

   	for(int k=1;k<=200;k++) {next[k]=new ArrayList<Integer>(); prev[k]=new ArrayList<Integer>();}
   	f[0][a[0]]++;
   	for(int i=1;i<n;i++)
   		{
   			for(int k=1;k<=200;k++) f[i][k]=f[i-1][k];
   			f[i][a[i]]++;
   		}

   	for(int i=0;i<n;i++)
   		{
   		   next[a[i]].add(i);
   		}

   	for(int i=n-1;i>=0;i--)
   		{
   		   prev[a[i]].add(i);
   		}

   	for(int k=1;k<=200;k++)
   		{
   			int l=left[k];
   			int r=right[k];

   			if(l==r || l==Integer.MAX_VALUE) continue;
   			if(r==l+1) {ans=Math.max(ans, 2);continue;}

   			int i=l;
   			int j=r;
   			int cnt=2;

   			int first_ind=1;
   			int last_ind=1;

   			while(i<j)
   				{
   					if(a[i]==a[j] && a[i]==k)
   						{
		   					int cur=cnt;
		   					int maxi=0;

		   					for(int p=1;p<=200;p++)
		   						{
		   							int pp=f[j-1][p]-f[i][p];
		   							maxi=Math.max(maxi, pp);
		   						}
		   					ans=Math.max(ans, cur+maxi);
		   					cnt+=2;
		   					i=next[k].get(first_ind++);
		   					j=prev[k].get(last_ind++);
   						}
   					else
   						{
   							if(a[i]!=k) i=next[k].get(first_ind++);
   							if(a[j]!=k) j=prev[k].get(last_ind++);
   						}
   				}
   		}
   	fans.append(ans+"\n");
   }

   public static void main(String[] args) throws java.lang.Exception
   {
	     s = new fast();
	     out=new PrintWriter(System.out);
	     fans=new StringBuilder("");

	     int t=s.nextInt();

	     while(t>0)
	    	 {
	    		 solve();
	    		 t--;
	    	 }

	    out.println(fans);
	    out.close();
   }

static class fast {

	   private InputStream i;
		private byte[]  buf = new byte[1024];
		private int curChar;

		private int numChars;

		//Return floor log2n
		public static long log2(long bits) // returns 0 for bits=0
			{
			    int log = 0;
			    if( ( bits & 0xffff0000 ) != 0 ) { bits >>>= 16; log = 16; }
			    if( bits >= 256 ) { bits >>>= 8; log += 8; }
			    if( bits >= 16  ) { bits >>>= 4; log += 4; }
			    if( bits >= 4   ) { bits >>>= 2; log += 2; }
			    return log + ( bits >>> 1 );
			}

		public static boolean next_permutation(int a[])
		   {
			   int i=0,j=0;int index=-1;
			   int n=a.length;

			   for(i=0;i<n-1;i++)
				   if(a[i]<a[i+1]) index=i;

			   if(index==-1) return false;
			   i=index;

			   for(j=i+1;j<n && a[i]<a[j];j++);

			   int temp=a[i];
			   a[i]=a[j-1];
			   a[j-1]=temp;

			   for(int p=i+1,q=n-1;p<q;p++,q--)
			   {
				   temp=a[p];
				   a[p]=a[q];
				   a[q]=temp;
			   }

			   return true;
		   }

		public static void division(char ch[],int divisor)
		   {
			   int div=Character.getNumericValue(ch[0]); int mul=10;int remainder=0;
			   StringBuilder quotient=new StringBuilder("");
			   for(int i=1;i<ch.length;i++)
			   {
				   div=div*mul+Character.getNumericValue(ch[i]);
				   if(div<divisor) {quotient.append("0");continue;}
				   quotient.append(div/divisor);
				   div=div%divisor;mul=10;

			   }
			   remainder=div;
			   while(quotient.charAt(0)=='0')quotient.deleteCharAt(0);
			   System.out.println(quotient+" "+remainder);
		   }

		public static void sieve(int size)
		{
			sieve=new int[size+1];

			primes=new ArrayList<Integer>();

			sieve[1]=1;

			for(int i=2;i*i<=size;i++)
			{
				if(sieve[i]==0)
				 {
					for(int j=i*i;j<size;j+=i) {sieve[j]=1;}
				 }
			}

			for(int i=2;i<=size;i++)
			{
				if(sieve[i]==0) primes.add(i);
			}
		}

		public static long pow(long n, long b, long MOD)
		   {
		       long x=1;long y=n;
		       while(b > 0)
		       {
		           if(b%2 == 1)
		           {
		               x=x*y;
		               if(x>MOD) x=x%(MOD);
		           }
		           y = y*y;
		           if(y>MOD) y=y%(MOD);
		           b >>= 1;
		       }
		       return x;
		   }

		public static long mod_inv(long n,long mod)
		{
			return pow(n,mod-2,mod);
		}

		//Returns index of highest number less than or equal to key
		 public static int upper(long[] a,int length,long key)
		 {
			    int low = 0;
		        int high = length-1;
		        int ans=-1;

		        while (low <= high) {
		            int mid = (low + high) / 2;
		            if (key >= a[mid]) {
		                ans=mid;
		            	low = mid+1;
		            } else if(a[mid]>key){
		                high = mid - 1;
		            }
		        }
		        return ans;
		}

		//Returns index of least number greater than or equal to key
		 public static int lower(long[] a,int length,long key)
		 {
			    int low = 0;
		        int high = length-1;
		        int ans=-1;

		        while (low <= high) {
		            int mid = (low + high) / 2;
		            if (key<=a[mid]) {
		                ans=mid;
		            	high = mid-1;
		            }
		            else{
		            		low=mid+1;
		            	}
		        }
		        return ans;
		}

		public long gcd(long r,long ans)
		{
			if(r==0) return ans;
			return gcd(ans%r,r);
		}
		public fast() {
			this(System.in);
		}
		public fast(InputStream is) {
			i = is;
		}
		public int read() {
			if (numChars == -1)
				throw new InputMismatchException();
			if (curChar >= numChars) {
				curChar = 0;
				try {
					numChars = i.read(buf);
				} catch (IOException e) {
					throw new InputMismatchException();
				}
				if (numChars <= 0)
					return -1;
			}
			return buf[curChar++];
		}
		public String nextLine() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			StringBuilder res = new StringBuilder();
			do {
				res.appendCodePoint(c);
				c = read();
			} while (!isEndOfLine(c));
			return res.toString();
		}
		public String nextString() {
     		int c = read();
			while (isSpaceChar(c))
				c = read();
			StringBuilder res = new StringBuilder();
			do {
				res.appendCodePoint(c);
				c = read();
			} while (!isSpaceChar(c));
			return res.toString();
		}
		public long nextLong() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			int sgn = 1;
			if (c == '-') {
				sgn = -1;
				c = read();
			}
			long res = 0;
			do {
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res *= 10;
				res += c - '0';
				c = read();
			} while (!isSpaceChar(c));
			return res * sgn;
		}
		public int nextInt() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			int sgn = 1;
			if (c == '-') {
				sgn = -1;
				c = read();
			}
			int res = 0;
			do {
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res *= 10;
				res += c - '0';
				c = read();
			} while (!isSpaceChar(c));
			return res * sgn;
		}
		public boolean isSpaceChar(int c) {
			return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
		}
		public boolean isEndOfLine(int c) {
			return c == '\n' || c == '\r' || c == -1;
		}

	}
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class ProblemE {

	public static void main(String[] args) {
		// TODO Auto-generated method stub

		FastReader s = new FastReader();
		int t = s.nextInt();
		for(int a = 0;a<t;a++) {
			int n = s.nextInt();

			int[] arr = new int[n];

			for(int i=0;i<n;i++)
				arr[i] = s.nextInt();

			int[][] cum = new int[n][201];

			for(int i=0;i<n;i++)
				for(int j=1;j<=200;j++) {

					if(i==0)
					{
						if(j==arr[0])
							cum[i][j] = 1;
					}
					else if(j == arr[i])
						cum[i][j] = cum[i-1][j] + 1;

					else
						cum[i][j] = cum[i-1][j];
				}

			int max = 1;

			for(int i=1;i<=200;i++) {
				max = Math.max(max, findMax(cum, arr, i));
			}

			System.out.println(max);
		}

	}

	public static int findMax(int[][] cum, int[] arr, int val) {

		int max = 0;
		int n = arr.length;
		int i=0, j = n-1;
		//System.out.println("hey"+val);
		int count = 0;
		while(true) {
			while(i < n && arr[i] != val)
				i++;
			//System.out.println(i);
			while(j > 0 && arr[j] != val)
				j--;

			if(i == n || j < 0 || i >= j)
				break;

			count++;
			int mx = 0;

			for(int k=1;k<=200;k++) {
				int df = cum[j-1][k] - cum[i][k];

				mx = Math.max(mx, df);
			}
			i++;
			j--;

			max = Math.max(max, mx + 2*count);
		}
		//System.out.println("returning");
		return max;
	}

	static class FastReader
    {
        BufferedReader br;
        StringTokenizer st;

        public FastReader()
        {
            br = new BufferedReader(new
                     InputStreamReader(System.in));
        }

        String next()
        {
            while (st == null || !st.hasMoreElements())
            {
                try
                {
                    st = new StringTokenizer(br.readLine());
                }
                catch (IOException  e)
                {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt()
        {
            return Integer.parseInt(next());
        }

        long nextLong()
        {
            return Long.parseLong(next());
        }

        double nextDouble()
        {
            return Double.parseDouble(next());
        }

        String nextLine()
        {
            String str = "";
            try
            {
                str = br.readLine();
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }
            return str;
        }
    }

}


import java.io.*;
import java.util.*;
import java.math.*;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class AA {
    public static void main(String[] args) throws IOException {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskA solver = new TaskA();
        solver.solve(in.nextInt(), in, out);
        out.close();
    }
    static class TaskA {
        long mod = (long)(1000000007);
        public void solve(int testNumber, InputReader in, PrintWriter out) throws IOException {
            while(testNumber-->0){
                int n = in.nextInt();
                int a[] = new int[n];
                for(int i=0;i<n;i++)
                    a[i] = in.nextInt();
                int x[][] = new int[201][n];
                for(int i=1;i<=n;i++){
                    int y = a[i-1];
                    if(i==1)
                        x[y][0]++;
                    else{
                        for(int j=1;j<=200;j++)
                            x[j][i-1] = x[j][i-2];
                        x[y][i-1]++;
                    }
                }
                ArrayList<ArrayList<Integer>> s = new ArrayList<>();
                for(int i=0;i<=200;i++)
                    s.add(new ArrayList<>());
                for(int i=0;i<n;i++)
                    s.get(a[i]).add(i);
                // out.println(s);
                HashSet<Integer> visited = new HashSet<>();
                int max = 0;
                for(int i=0;i<n;i++){
                    if(visited.add(a[i])){
                        if(s.get(a[i]).size()==0)
                            continue;
                        max = Math.max(max , s.get(a[i]).size());
                        // out.println("max " + max);

                        int starti = 0;
                        int endi = s.get(a[i]).size()-1;
                        int start = s.get(a[i]).get(starti);
                        int end = s.get(a[i]).get(endi);
                        int count = 2;
                        while(start<end){
                            int max2 = 0;
                            // out.println(start + " " + end);
                            for(int j=0;j<=200;j++){
                                max2 = Math.max(x[j][end-1] - x[j][start] , max2);
                            }
                            // out.println("max2 " + max2);
                            try{
                                start = s.get(a[i]).get(++starti);
                                end = s.get(a[i]).get(--endi);
                                max = Math.max(max , count + max2);
                            }
                            catch(Exception e){
                                break;
                            }
                            count+=2;
                        }

                    }
                }
                out.println(max);
                // out.println();
                // for(int i=0;i<=200;i++){
                //     for(int j=0;j<n;j++)
                //         out.print(x[i][j] + " ");
                //     out.println();
                // }
            }
        }
        public void sieve(int a[]){
            a[0] = a[1] = 1;
            int i;
            for(i=2;i*i<=a.length;i++){
                if(a[i] != 0)
                    continue;
                a[i] = i;
                for(int k = (i)*(i);k<a.length;k+=i){
                    if(a[k] != 0)
                        continue;
                    a[k] = i;
                }
            }
        }
        public int [][] matrixExpo(int c[][] , int n){
            int a[][] = new int[c.length][c[0].length];
            int b[][] = new int[a.length][a[0].length];
            for(int i=0;i<c.length;i++)
                for(int j=0;j<c[0].length;j++)
                    a[i][j] = c[i][j];
            for(int i=0;i<a.length;i++)
                b[i][i] = 1;
            while(n!=1){
                if(n%2 == 1){
                    b = matrixMultiply(a , a);
                    n--;
                }
                a = matrixMultiply(a , a);
                n/=2;
            }
            return matrixMultiply(a , b);
        }
        public int [][] matrixMultiply(int a[][] , int b[][]){
            int r1 = a.length;
            int c1 = a[0].length;
            int c2 = b[0].length;
            int c[][] = new int[r1][c2];
            for(int i=0;i<r1;i++){
                for(int j=0;j<c2;j++){
                    for(int k=0;k<c1;k++)
                        c[i][j] += a[i][k]*b[k][j];
                }
            }
            return c;
        }
        public long nCrPFermet(int n , int r , long p){
            if(r==0)
                return 1l;
            long fact[] = new long[n+1];
            fact[0] = 1;
            for(int i=1;i<=n;i++)
                fact[i] = (i*fact[i-1])%p;
            long modInverseR = pow(fact[r] , p-2 , 1l , p);
            long modInverseNR = pow(fact[n-r] , p-2 , 1l , p);
            long w = (((fact[n]*modInverseR)%p)*modInverseNR)%p;
            return w;
        }
        public long pow(long a , long b , long res , long mod){
            if(b==0)
                return res;
            if(b==1)
                return (res*a)%mod;
            if(b%2==1){
                res *= a;
                res %= mod;
                b--;
            }
            // System.out.println(a + " " + b + " " + res);
            return pow((a*a)%mod , b/2 , res , mod);
        }
        public long pow(long a , long b , long res){
            if(b == 0)
                return res;
            if(b==1)
                return res*a;
            if(b%2==1){
                res *= a;
                b--;
            }
            return pow(a*a , b/2 , res);
        }
        public void swap(int a[] , int p1 , int p2){
            int x = a[p1];
            a[p1] = a[p2];
            a[p2] = x;
        }
        public void sortedArrayToBST(TreeSet<Integer> a , int start, int end) {
            if (start > end) {
                return;
            }
            int mid = (start + end) / 2;
            a.add(mid);
            sortedArrayToBST(a, start, mid - 1);
            sortedArrayToBST(a, mid + 1, end);
        }
        class Combine{
            int value;
            int delete;
            Combine(int val , int delete){
                this.value = val;
                this.delete = delete;
            }
        }
        class Sort2 implements Comparator<Combine>{
            public int compare(Combine a , Combine b){
                if(a.value > b.value)
                    return 1;
                else if(a.value == b.value && a.delete>b.delete)
                    return 1;
                else if(a.value == b.value && a.delete == b.delete)
                    return 0;
                return -1;
            }
        }
        public int lowerLastBound(ArrayList<Integer> a , int x){
            int l = 0;
            int r = a.size()-1;
            if(a.get(l)>=x)
                return -1;
            if(a.get(r)<x)
                return r;
            int mid = -1;
            while(l<=r){
                mid = (l+r)/2;
                if(a.get(mid) == x && a.get(mid-1)<x)
                    return mid-1;
                else if(a.get(mid)>=x)
                    r = mid-1;
                else if(a.get(mid)<x && a.get(mid+1)>=x)
                    return mid;
                else if(a.get(mid)<x && a.get(mid+1)<x)
                    l = mid+1;
            }
            return mid;
        }
        public int upperFirstBound(ArrayList<Integer> a , Integer x){
            int l = 0;
            int r = a.size()-1;
            if(a.get(l)>x)
                return l;
            if(a.get(r)<=x)
                return r+1;
            int mid = -1;
            while(l<=r){
                mid = (l+r)/2;
                if(a.get(mid) == x && a.get(mid+1)>x)
                    return mid+1;
                else if(a.get(mid)<=x)
                    l = mid+1;
                else if(a.get(mid)>x && a.get(mid-1)<=x)
                    return mid;
                else if(a.get(mid)>x && a.get(mid-1)>x)
                    r = mid-1;
            }
            return mid;
        }
        public int lowerLastBound(int a[] , int x){
            int l = 0;
            int r = a.length-1;
            if(a[l]>=x)
                return -1;
            if(a[r]<x)
                return r;
            int mid = -1;
            while(l<=r){
                mid = (l+r)/2;
                if(a[mid] == x && a[mid-1]<x)
                    return mid-1;
                else if(a[mid]>=x)
                    r = mid-1;
                else if(a[mid]<x && a[mid+1]>=x)
                    return mid;
                else if(a[mid]<x && a[mid+1]<x)
                    l = mid+1;
            }
            return mid;
        }
        public int upperFirstBound(long a[] , long x){
            int l = 0;
            int r = a.length-1;
            if(a[l]>x)
                return l;
            if(a[r]<=x)
                return r+1;
            int mid = -1;
            while(l<=r){
                mid = (l+r)/2;
                if(a[mid] == x && a[mid+1]>x)
                    return mid+1;
                else if(a[mid]<=x)
                    l = mid+1;
                else if(a[mid]>x && a[mid-1]<=x)
                    return mid;
                else if(a[mid]>x && a[mid-1]>x)
                    r = mid-1;
            }
            return mid;
        }
        public long log(float number , int base){
            return (long) Math.floor((Math.log(number) / Math.log(base)));
        }
        public long gcd(long a , long b){
            if(a<b){
                long c = b;
                b = a;
                a = c;
            }
            if(b == 0)
                return a;
            return gcd(b , a%b);
        }
        public void print2d(long a[][] , PrintWriter out){
            for(int i=0;i<a.length;i++){
                for(int j=0;j<a[i].length;j++)
                    out.print(a[i][j] + " ");
                out.println();
            }
            out.println();
        }
        public void print1d(int a[] , PrintWriter out){
            for(int i=0;i<a.length;i++)
                out.print(a[i] + " ");
            out.println();
            out.println();
        }
    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public long nextLong() {
            return Long.parseLong(next());
        }

    }
}


import java.io.*;
import java.util.*;
import java.math.*;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class AA {
    public static void main(String[] args) throws IOException {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskA solver = new TaskA();
        solver.solve(in.nextInt(), in, out);
        out.close();
    }
    static class TaskA {
        long mod = (long)(1000000007);
        public void solve(int testNumber, InputReader in, PrintWriter out) throws IOException {
            while(testNumber-->0){
                int n = in.nextInt();
                int a[] = new int[n];
                for(int i=0;i<n;i++)
                    a[i] = in.nextInt();
                int x[][] = new int[201][n];
                for(int i=1;i<=n;i++){
                    int y = a[i-1];
                    if(i==1)
                        x[y][0]++;
                    else{
                        for(int j=1;j<=200;j++)
                            x[j][i-1] = x[j][i-2];
                        x[y][i-1]++;
                    }
                }
                ArrayList<ArrayList<Integer>> s = new ArrayList<>();
                for(int i=0;i<=200;i++)
                    s.add(new ArrayList<>());
                for(int i=0;i<n;i++)
                    s.get(a[i]).add(i);
                HashSet<Integer> visited = new HashSet<>();
                int max = 0;
                for(int i=0;i<n;i++){
                    if(visited.add(a[i])){
                        if(s.get(a[i]).size()==0)
                            continue;
                        max = Math.max(max , s.get(a[i]).size());
                        int starti = 0;
                        int endi = s.get(a[i]).size()-1;
                        int start = s.get(a[i]).get(starti);
                        int end = s.get(a[i]).get(endi);
                        int max2 = 0;
                        int count = 2;
                        while(start+1<end){
                            for(int j=0;j<=200;j++){
                                max2 = Math.max(x[j][end-1] - x[j][start] , max2);
                            }
                            try{
                                start = s.get(a[i]).get(++starti);
                                end = s.get(a[i]).get(--endi);
                                max = Math.max(max , count + max2);
                            }
                            catch(Exception e){
                                break;
                            }
                            count+=2;
                        }

                    }
                }
                out.println(max);
                // for(int i=0;i<=200;i++){
                //     for(int j=0;j<n;j++)
                //         out.print(x[i][j] + " ");
                //     out.println();
                // }
            }
        }
        public void sieve(int a[]){
            a[0] = a[1] = 1;
            int i;
            for(i=2;i*i<=a.length;i++){
                if(a[i] != 0)
                    continue;
                a[i] = i;
                for(int k = (i)*(i);k<a.length;k+=i){
                    if(a[k] != 0)
                        continue;
                    a[k] = i;
                }
            }
        }
        public int [][] matrixExpo(int c[][] , int n){
            int a[][] = new int[c.length][c[0].length];
            int b[][] = new int[a.length][a[0].length];
            for(int i=0;i<c.length;i++)
                for(int j=0;j<c[0].length;j++)
                    a[i][j] = c[i][j];
            for(int i=0;i<a.length;i++)
                b[i][i] = 1;
            while(n!=1){
                if(n%2 == 1){
                    b = matrixMultiply(a , a);
                    n--;
                }
                a = matrixMultiply(a , a);
                n/=2;
            }
            return matrixMultiply(a , b);
        }
        public int [][] matrixMultiply(int a[][] , int b[][]){
            int r1 = a.length;
            int c1 = a[0].length;
            int c2 = b[0].length;
            int c[][] = new int[r1][c2];
            for(int i=0;i<r1;i++){
                for(int j=0;j<c2;j++){
                    for(int k=0;k<c1;k++)
                        c[i][j] += a[i][k]*b[k][j];
                }
            }
            return c;
        }
        public long nCrPFermet(int n , int r , long p){
            if(r==0)
                return 1l;
            long fact[] = new long[n+1];
            fact[0] = 1;
            for(int i=1;i<=n;i++)
                fact[i] = (i*fact[i-1])%p;
            long modInverseR = pow(fact[r] , p-2 , 1l , p);
            long modInverseNR = pow(fact[n-r] , p-2 , 1l , p);
            long w = (((fact[n]*modInverseR)%p)*modInverseNR)%p;
            return w;
        }
        public long pow(long a , long b , long res , long mod){
            if(b==0)
                return res;
            if(b==1)
                return (res*a)%mod;
            if(b%2==1){
                res *= a;
                res %= mod;
                b--;
            }
            // System.out.println(a + " " + b + " " + res);
            return pow((a*a)%mod , b/2 , res , mod);
        }
        public long pow(long a , long b , long res){
            if(b == 0)
                return res;
            if(b==1)
                return res*a;
            if(b%2==1){
                res *= a;
                b--;
            }
            return pow(a*a , b/2 , res);
        }
        public void swap(int a[] , int p1 , int p2){
            int x = a[p1];
            a[p1] = a[p2];
            a[p2] = x;
        }
        public void sortedArrayToBST(TreeSet<Integer> a , int start, int end) {
            if (start > end) {
                return;
            }
            int mid = (start + end) / 2;
            a.add(mid);
            sortedArrayToBST(a, start, mid - 1);
            sortedArrayToBST(a, mid + 1, end);
        }
        class Combine{
            int value;
            int delete;
            Combine(int val , int delete){
                this.value = val;
                this.delete = delete;
            }
        }
        class Sort2 implements Comparator<Combine>{
            public int compare(Combine a , Combine b){
                if(a.value > b.value)
                    return 1;
                else if(a.value == b.value && a.delete>b.delete)
                    return 1;
                else if(a.value == b.value && a.delete == b.delete)
                    return 0;
                return -1;
            }
        }
        public int lowerLastBound(ArrayList<Integer> a , int x){
            int l = 0;
            int r = a.size()-1;
            if(a.get(l)>=x)
                return -1;
            if(a.get(r)<x)
                return r;
            int mid = -1;
            while(l<=r){
                mid = (l+r)/2;
                if(a.get(mid) == x && a.get(mid-1)<x)
                    return mid-1;
                else if(a.get(mid)>=x)
                    r = mid-1;
                else if(a.get(mid)<x && a.get(mid+1)>=x)
                    return mid;
                else if(a.get(mid)<x && a.get(mid+1)<x)
                    l = mid+1;
            }
            return mid;
        }
        public int upperFirstBound(ArrayList<Integer> a , Integer x){
            int l = 0;
            int r = a.size()-1;
            if(a.get(l)>x)
                return l;
            if(a.get(r)<=x)
                return r+1;
            int mid = -1;
            while(l<=r){
                mid = (l+r)/2;
                if(a.get(mid) == x && a.get(mid+1)>x)
                    return mid+1;
                else if(a.get(mid)<=x)
                    l = mid+1;
                else if(a.get(mid)>x && a.get(mid-1)<=x)
                    return mid;
                else if(a.get(mid)>x && a.get(mid-1)>x)
                    r = mid-1;
            }
            return mid;
        }
        public int lowerLastBound(int a[] , int x){
            int l = 0;
            int r = a.length-1;
            if(a[l]>=x)
                return -1;
            if(a[r]<x)
                return r;
            int mid = -1;
            while(l<=r){
                mid = (l+r)/2;
                if(a[mid] == x && a[mid-1]<x)
                    return mid-1;
                else if(a[mid]>=x)
                    r = mid-1;
                else if(a[mid]<x && a[mid+1]>=x)
                    return mid;
                else if(a[mid]<x && a[mid+1]<x)
                    l = mid+1;
            }
            return mid;
        }
        public int upperFirstBound(long a[] , long x){
            int l = 0;
            int r = a.length-1;
            if(a[l]>x)
                return l;
            if(a[r]<=x)
                return r+1;
            int mid = -1;
            while(l<=r){
                mid = (l+r)/2;
                if(a[mid] == x && a[mid+1]>x)
                    return mid+1;
                else if(a[mid]<=x)
                    l = mid+1;
                else if(a[mid]>x && a[mid-1]<=x)
                    return mid;
                else if(a[mid]>x && a[mid-1]>x)
                    r = mid-1;
            }
            return mid;
        }
        public long log(float number , int base){
            return (long) Math.floor((Math.log(number) / Math.log(base)));
        }
        public long gcd(long a , long b){
            if(a<b){
                long c = b;
                b = a;
                a = c;
            }
            if(b == 0)
                return a;
            return gcd(b , a%b);
        }
        public void print2d(long a[][] , PrintWriter out){
            for(int i=0;i<a.length;i++){
                for(int j=0;j<a[i].length;j++)
                    out.print(a[i][j] + " ");
                out.println();
            }
            out.println();
        }
        public void print1d(int a[] , PrintWriter out){
            for(int i=0;i<a.length;i++)
                out.print(a[i] + " ");
            out.println();
            out.println();
        }
    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public long nextLong() {
            return Long.parseLong(next());
        }

    }
}


import java.io.*;
import java.math.BigInteger;
import java.util.*;

/*
Прокрастинирую
*/

public class Main {

    static FastReader in;
    static PrintWriter out;
    static Random rand = new Random();
    static final int INF = (int) (1e9 + 10), MOD = (int) (998244353), LOGN = 60;
    static final long IINF = (long) (2e18 + 10);
    static final int N = (int) (1e5 + 5);

    static int lower(ArrayList<Integer> list, int x) {
        if (list.size() == 0 || list.get(0) > x) {
            return 0;
        }
        int l = 0, r = list.size() - 1;
        while (l < r) {
            int m = (l + r + 1) / 2;
            if (list.get(m) <= x) {
                l = m;
            } else {
                r = m - 1;
            }
        }
        return l + 1;
    }

    static void solve() {
        int n = in.nextInt();

        int[] a = new int[n];
        ArrayList<Integer>[] cols = new ArrayList[202];
        Arrays.setAll(cols, col -> new ArrayList<>());
        for (int i = 0; i < n; i++) {
            a[i] = in.nextInt();
            cols[a[i]].add(i);
        }

        int ans = 0;
        for (int i = 1; i <= 200; i++) {
            for (int j = 1; j <= 200; j++) {
                if (i == j) {
                    ans = Math.max(ans, cols[i].size());
                } else {
                    if (cols[i].size() == 0 || cols[j].size() == 0) {
                        continue;
                    }
                    for (int k = 1; k <= cols[i].size() / 2; k++) {
                        int i1 = cols[i].get(k - 1);
                        int cnt1 = lower(cols[j], i1);
                        int i2 = cols[i].get(cols[i].size() - k);
                        int cnt2 = lower(cols[j], i2);
                        int len = cnt2 - cnt1 + k * 2;
                        ans = Math.max(ans, len);
                    }
                }
            }
        }

        out.println(ans);
    }

    public static void main(String[] args) throws FileNotFoundException, InterruptedException {
        in = new FastReader(System.in);
//        in = new FastReader(new FileInputStream("input.txt"));
        out = new PrintWriter(System.out);
//        out = new PrintWriter(new FileOutputStream("output.txt"));

        Thread thread = new Thread(null, () -> {
            int tests = 1;
            tests = in.nextInt();

            while (tests-- > 0) {
                solve();
            }
        }, "Go", 1 << 28);
        thread.start();
        thread.join();

//        out.flush();
        out.close();
    }

    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        FastReader(InputStream is) {
            br = new BufferedReader(new InputStreamReader(is));
        }

        Integer nextInt() {
            return Integer.parseInt(next());
        }

        Long nextLong() {
            return Long.parseLong(next());
        }

        Double nextDouble() {
            return Double.parseDouble(next());
        }

        String next() {
            while (st == null || !st.hasMoreTokens()) {
                st = new StringTokenizer(nextLine());
            }
            return st.nextToken();
        }

        String nextLine() {
            String s = "";
            try {
                s = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return s;
        }
    }
}


import java.io.*;
import java.math.BigInteger;
import java.util.*;

/*
Прокрастинирую
*/

public class Main {

    static FastReader in;
    static PrintWriter out;
    static Random rand = new Random();
    static final int INF = (int) (1e9 + 10), MOD = (int) (998244353), LOGN = 60;
    static final long IINF = (long) (2e18 + 10);
    static final int N = (int) (1e5 + 5);

    static void solve() {
        int n = in.nextInt();

        int[] a = new int[n];
        ArrayList<Integer>[] cols = new ArrayList[202];
        Arrays.setAll(cols, col -> new ArrayList<>());
        for (int i = 0; i < n; i++) {
            a[i] = in.nextInt();
            cols[a[i]].add(i);
        }

        int ans = 0;
        for (int i = 1; i <= 200; i++) {
            for (int j = 1; j <= 200; j++) {
                if (i == j) {
                    ans = Math.max(ans, cols[i].size());
                } else {
                    for (int k = 1, l = 0, r = cols[j].size() - 1; k <= cols[i].size() / 2; k++) {
                        while (l <= r && cols[j].get(l) < cols[i].get(k - 1)) l++;
                        while (l <= r && cols[j].get(r) > cols[i].get(cols[i].size() - k)) r--;
                        ans = Math.max(ans, k * 2 + r - l + 1);
                    }
                }
            }
        }

        out.println(ans);
    }

    public static void main(String[] args) throws FileNotFoundException, InterruptedException {
        in = new FastReader(System.in);
//        in = new FastReader(new FileInputStream("input.txt"));
        out = new PrintWriter(System.out);
//        out = new PrintWriter(new FileOutputStream("output.txt"));

        Thread thread = new Thread(null, () -> {
            int tests = 1;
            tests = in.nextInt();

            while (tests-- > 0) {
                solve();
            }
        }, "Go", 1 << 28);
        thread.start();
        thread.join();

//        out.flush();
        out.close();
    }

    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        FastReader(InputStream is) {
            br = new BufferedReader(new InputStreamReader(is));
        }

        Integer nextInt() {
            return Integer.parseInt(next());
        }

        Long nextLong() {
            return Long.parseLong(next());
        }

        Double nextDouble() {
            return Double.parseDouble(next());
        }

        String next() {
            while (st == null || !st.hasMoreTokens()) {
                st = new StringTokenizer(nextLine());
            }
            return st.nextToken();
        }

        String nextLine() {
            String s = "";
            try {
                s = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return s;
        }
    }
}


/* package codechef; // don't place package name! */

import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
public class p52
{
         static class Input {
        private StringTokenizer tokenizer = null;
        private BufferedReader reader;

        public Input(InputStream inputStream) {
            reader = new BufferedReader(new InputStreamReader(inputStream));
        }

        public String nextLine() {
            try {
                return reader.readLine();
            } catch (IOException e) {
                throw new RuntimeException();
            }
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                tokenizer = new StringTokenizer(nextLine());
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public long nextLong() {
            return Long.parseLong(next());
        }

        public int[] nextIntArray(int n, int add) {
            int[] result = new int[n];
            for (int i = 0; i < n; i++) {
                result[i] = nextInt() + add;
            }
            return result;
        }

        public long[] nextLongArray(int n, long add) {
            long[] result = new long[n];
            for (int i = 0; i < n; i++) {
                result[i] = nextLong() + add;
            }
            return result;
        }

        public int[] nextIntArray(int n) {
            return nextIntArray(n, 0);
        }

    }

	public static void main (String[] args) throws java.lang.Exception
	{
		Input s=new Input(System.in);
		int t=s.nextInt();
		PrintWriter out=new PrintWriter(System.out);

		while(t-->0)
		{
            int n=s.nextInt();
            int a[]=s.nextIntArray(n);
            int pref[][]=new int[201][n];
            pref[a[0]][0]=1;
            ArrayList<Integer> arr[]=new ArrayList[201];
            for(int i=0;i<201;i++)arr[i]=new ArrayList<Integer>();
            arr[a[0]].add(0);
            for(int i=1;i<n;i++)
            {
                pref[a[i]][i]=pref[a[i]][i-1]+1;
                arr[a[i]].add(i);
                for(int j=1;j<=200;j++)
                if(j!=a[i])
                pref[j][i]=pref[j][i-1];
            }

            int ans=1;
                    int cout=0,cin=0;
              for(int i=1;i<=200;i++){

                    for(int k=0;k<arr[i].size()/2;k++)
                    {
                        int l=arr[i].get(k);
                        int r=arr[i].get(arr[i].size()-1-k);
                        cout=k+1;
                        cin=0;
                        for(int j=1;j<=200;j++)
                            cin=Math.max(cin,pref[j][r-1]-pref[j][l]);
                        ans=Math.max(ans,cin+2*cout);
                        //if(i==1)
                        //out.println(k+" "+ans);
                    }

                }

            out.println(ans);
        }
        out.flush();
	}
}


import java.util.*;
import java.io.*;
public class A
{
      public static void main(String ar[]) throws Exception
      {
            BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
            int t=Integer.parseInt(br.readLine());
            for(int x=0;x<t;x++)
            {
                  int n=Integer.parseInt(br.readLine());

                  int a[]=new int[n];
                  String s1[]=br.readLine().split(" ");
                  for(int i=0;i<n;i++)
                   a[i]=Integer.parseInt(s1[i]);

                  // int l[]=new int[201];
                  // int r[][]=new int[201][n+1];
                  // int pos[]=new int[201];

                  // for(int i=n-1;i>=0;i--)
                  // {
                  //       int u=a[i];
                  //       int p=pos[u];

                  //       r[u][p+1]=i;
                  //       pos[u]=p+1;
                  // }

                  int pre[][]=new int[201][n];
                  for(int i=0;i<n;i++)
                  {
                        pre[a[i]][i]=1;
                        for(int j=1;i>0 && j<=200;j++)
                         pre[j][i]+=pre[j][i-1];
                  }

                  int c=1;
                  for(int i=0;i<n;i++)
                  {
                        //l[a[i]]++;
                        int u=a[i];
                        int m=pre[u][i];
                        //int p=r[u][m];

                        int total=pre[u][n-1];
                        if(total<2*m)
                         continue;

                        total-=m;
                        int lo=0,hi=n-1;
                        while(hi-lo>1)
                        {
                              int mid=(lo+hi)/2;
                              if(pre[u][mid]>total)
                              { hi=mid;  }
                              else
                              { lo=mid;  }
                        }

                        if(hi-lo<=1)
                        {
                            if(pre[u][hi]==total)
                              { lo=hi;  }
                              else
                              { hi=lo;  }
                        }

                        int p=lo+1;
                        //System.out.println(u+" "+m+" "+p+" "+total);
                        // System.out.println(Arrays.toString(pre[u]));

                        // if(p<=i)
                        //  continue;

                        //System.out.println();
                        int max=0;
                        for(int j=1;j<=200;j++)
                        {
                              max=Math.max(max,pre[j][p-1]-pre[j][i]);
                        }

                        c=Math.max(c,2*m+max);
                  }

                  System.out.println(c);
            }
      }
}


import java.util.*;
import java.io.*;
public class A
{
      public static void main(String ar[]) throws Exception
      {
            BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
            int t=Integer.parseInt(br.readLine());
            for(int x=0;x<t;x++)
            {
                  int n=Integer.parseInt(br.readLine());

                  int a[]=new int[n];
                  String s1[]=br.readLine().split(" ");
                  for(int i=0;i<n;i++)
                   a[i]=Integer.parseInt(s1[i]);

                  int l[]=new int[201];
                  int r[][]=new int[201][n+1];
                  int pos[]=new int[201];

                  for(int i=n-1;i>=0;i--)
                  {
                        int u=a[i];
                        int p=pos[u];

                        r[u][p+1]=i;
                        pos[u]=p+1;
                  }

                  int pre[][]=new int[201][n];
                  for(int i=0;i<n;i++)
                  {
                        pre[a[i]][i]=1;
                        for(int j=1;i>0 && j<=200;j++)
                         pre[j][i]+=pre[j][i-1];
                  }

                  int c=1;
                  for(int i=0;i<n;i++)
                  {
                        l[a[i]]++;
                        int u=a[i];
                        int m=l[a[i]];
                        int p=r[u][m];
                        if(p<=i)
                         continue;

                        int max=0;
                        for(int j=1;j<=200;j++)
                        {
                              max=Math.max(max,pre[j][p-1]-pre[j][i]);
                        }

                        c=Math.max(c,2*m+max);
                  }

                  System.out.println(c);
            }
      }
}


import java.util.*;
import java.io.*;
public class A
{
      public static void main(String ar[]) throws Exception
      {
            BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
            int t=Integer.parseInt(br.readLine());
            for(int x=0;x<t;x++)
            {
                  int n=Integer.parseInt(br.readLine());

                  int a[]=new int[n];
                  String s1[]=br.readLine().split(" ");
                  for(int i=0;i<n;i++)
                   a[i]=Integer.parseInt(s1[i]);

                  // int l[]=new int[201];
                  // int r[][]=new int[201][n+1];
                  // int pos[]=new int[201];

                  // for(int i=n-1;i>=0;i--)
                  // {
                  //       int u=a[i];
                  //       int p=pos[u];

                  //       r[u][p+1]=i;
                  //       pos[u]=p+1;
                  // }

                  int pre[][]=new int[201][n];
                  for(int i=0;i<n;i++)
                  {
                        pre[a[i]][i]=1;
                        for(int j=1;i>0 && j<=200;j++)
                         pre[j][i]+=pre[j][i-1];
                  }

                  int c=1;
                  for(int i=0;i<n;i++)
                  {
                        //l[a[i]]++;
                        int u=a[i];
                        int m=pre[u][i];
                        //int p=r[u][m];

                        int total=pre[u][n-1];
                        if(total<2*m)
                         continue;

                        total-=m;
                        int lo=0,hi=n-1;
                        while(hi-lo>1)
                        {
                              int mid=(lo+hi)/2;
                              if(pre[u][mid]>=total)
                              { lo=mid;  }
                              else
                              { hi=mid;  }
                        }

                        if(hi-lo<=1)
                        {
                            if(pre[u][hi]==total)
                              { lo=hi;  }
                              else
                              { hi=lo;  }
                        }

                        int p=lo+1;
                        // System.out.println(u+" "+m+" "+p+" "+total);
                        // System.out.println(Arrays.toString(pre[u]));

                        if(p<=i)
                         continue;

                        int max=0;
                        for(int j=1;j<=200;j++)
                        {
                              max=Math.max(max,pre[j][p-1]-pre[j][i]);
                        }

                        c=Math.max(c,2*m+max);
                  }

                  System.out.println(c);
            }
      }
}


import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.StringTokenizer;

public class COVID {

static SparseTable st;
static HashMap<Integer,Long> cnt;
static int n;

public static void main(String[] args) throws Exception {
	//	Scanner sc = new Scanner(System.in);
		PrintWriter pw =new PrintWriter(System.out);
		BufferedReader bf= new BufferedReader(new InputStreamReader(System.in));
		 int t= Integer.parseInt(bf.readLine());
		 while(t-->0) {
			 int n=Integer.parseInt(bf.readLine());
			 StringTokenizer st= new StringTokenizer(bf.readLine());
			 int[][] freq= new int[201][n];
			 ArrayList<Integer>[] loc=new ArrayList[201];
			 for(int i=0;i<201;i++)loc[i]=new ArrayList();

			 HashSet<Integer> set=new HashSet();
			 for(int i=0;i<n;i++) {
				 int a=Integer.parseInt(st.nextToken());
				 freq[a][i]=1;
				 loc[a].add(i);
				 set.add(a);
			 }
			 int max=0;
			 for(int i=0;i<201;i++)
			 {
				 for(int j=0;j<n;j++)
					 freq[i][j]+= ((j==0)?0:freq[i][j-1]);

				 max=Math.max(max, freq[i][n-1]);
			 }
//			 System.out.println(max);
			 for(int i=1;i<201;i++) {
				 if(!set.contains(i))continue;

				 for(int j=0;(j+1)<<1<=loc[i].size();j++)
				 {
					 int s=loc[i].get(j);
					 int e=loc[i].get(loc[i].size()-j-1);
//					 System.out.println(s+" "+e+" "+j);
				//	 System.out.println("***"+ freq[10][3]+" "+freq[10][0]);
					 for(int k=1;k<201;k++) {
						 if(!set.contains(k))continue;
//						 System.out.println(freq[i][s]+" "+k+" -- "+(freq[k][e-1]-freq[k][s]));
//						 System.out.println((freq[i][s]<<1) + freq[k][e-1]-freq[k][s]);
						 max=Math.max(max, (freq[i][s]<<1) + freq[k][e-1]-freq[k][s]);
					 }
				 }

			 }
			 pw.println(max);

		 }
		pw.flush();

}
		static void BS(int i,int start ,int lo , int hi, int val) {

			int l =lo,r=hi;
			while(lo<=hi) {
				int mid=lo+hi>>1;
				if( (st.query(i,mid))>=val) {
					lo=mid+1;
				}else {
					hi=mid-1;
				}
			}
		//	System.out.println(val+" "+hi+" "+start);
			cnt.put(val,cnt.getOrDefault(val, 0l)+hi-start+1);
			hi++;
			if(hi==n)return;
			BS(i,hi,hi,n-1,st.query(i, hi));

		}

static class SparseTable{
int[][] spt;
int n;
int k;
int[] log;
static int gcd(int a ,int b) {
	return (a==0)?b:gcd(b%a,a);
}

public SparseTable(int[] arr) {
	n=arr.length;

	k=(int)( Math.floor(Math.log(arr.length)/Math.log(2))+1);
	spt=new int[n][k];
	for(int i=0;i<n;i++)spt[i][0]=arr[i];

	for(int j=1;j<=k;j++)
		for(int i=0;i+(1<<j)-1<n;i++)
			spt[i][j]=gcd(spt[i][j-1],spt[i+(1<<(j-1))][j-1]);

	log=new int[n+1];
	for(int i=2;i<=n;i++)
		log[i]=log[i/2]+1;
}
public int query(int l , int r) {
	int k=log[r-l+1];
	return gcd(spt[l][k],spt[r-(1<<k)+1][k]);
}

}
static class Pair implements Comparable<Pair>{
	long  x;int y,z;
	public Pair(long a,int b, int c) {
		this.x=a;y=b;this.z=c;
	}

	public int compareTo(Pair o) {
		//return (this.x==o.x)?(this.y==o.y)?z-o.z:this.y-o.y:this.x-o.x;
		return this.x>o.x?1:(this.x<o.x)?-1:0;
	}

}

static class Scanner {
	StringTokenizer st;
	BufferedReader br;

	public Scanner(InputStream s) {
		br = new BufferedReader(new InputStreamReader(s));
	}
	public Scanner(String s) throws FileNotFoundException{	br = new BufferedReader(new FileReader(s));}

	public String next() throws IOException {
		while (st == null || !st.hasMoreTokens())
			st = new StringTokenizer(br.readLine()," ,");
		return st.nextToken();
	}

	public int nextInt() throws IOException {
		return Integer.parseInt(next());
	}

	public long nextLong() throws IOException {
		return Long.parseLong(next());
	}

	public String nextLine() throws IOException {
		return br.readLine();
	}

	public double nextDouble() throws IOException {
		String x = next();
		StringBuilder sb = new StringBuilder("0");
		double res = 0, f = 1;
		boolean dec = false, neg = false;
		int start = 0;
		if (x.charAt(0) == '-') {
			neg = true;
			start++;
		}
		for (int i = start; i < x.length(); i++) {
			if (x.charAt(i) == '.') {
				res = Long.parseLong(sb.toString());
				sb = new StringBuilder("0");
				dec = true;
			} else {
				sb.append(x.charAt(i));
				if (dec)
					f *= 10;
			}
			if (sb.length() == 18) {
				res += Long.parseLong(sb.toString()) / f;
				sb = new StringBuilder("0");
			}
		}
		res += Long.parseLong(sb.toString()) / f;
		return res * (neg ? -1 : 1);
	}

	public boolean ready() throws IOException {
		return br.ready();
	}

}

public static void shuffle(int[] a) {
	int n = a.length;
	for (int i = 0; i < n; i++) {
		int r = i + (int) (Math.random() * (n - i));
		int tmp = a[i];
		a[i] = a[r];
		a[r] = tmp;
	}
}
}


import java.util.*;
import java.lang.*;
import java.io.*;
import java.math.*;
public class Prac{
    static class InputReader {
        private final InputStream stream;
        private final byte[] buf = new byte[8192];
        private int curChar, snumChars;
        public InputReader(InputStream st) {
            this.stream = st;
        }
        public int read() {
            if (snumChars == -1)
                throw new InputMismatchException();
            if (curChar >= snumChars) {
                curChar = 0;
                try {
                    snumChars = stream.read(buf);
                }
                catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (snumChars <= 0)
                    return -1;
            }
            return buf[curChar++];
        }
        public int ni() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            int res = 0;
            do {
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }
        public long nl() {
            int c = read();
            while (isSpaceChar(c)) {
            c = read();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            long res = 0;
            do {
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }
        public int[] nia(int n) {
            int a[] = new int[n];
            for (int i = 0; i < n; i++) {
                a[i] = ni();
            }
            return a;
        }
        public String rs() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            StringBuilder res = new StringBuilder();
            do {
                res.appendCodePoint(c);
                    c = read();
            } while (!isSpaceChar(c));
            return res.toString();
        }
        public String nextLine() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            StringBuilder res = new StringBuilder();
            do {
                res.appendCodePoint(c);
                c = read();
            } while (!isEndOfLine(c));
            return res.toString();
        }
        public boolean isSpaceChar(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        private boolean isEndOfLine(int c) {
            return c == '\n' || c == '\r' || c == -1;
        }
    }
    public static class Key {

        private final int x;
        private final int y;

        public Key(int x, int y) {
            this.x = x;
            this.y = y;
        }

        @Override
        public boolean equals(Object o) {
            if (this == o) return true;
            if (!(o instanceof Key)) return false;
            Key key = (Key) o;
            return x == key.x && y == key.y;
        }

        @Override
        public int hashCode() {
            int result = x;
            result = 31 * result + y;
            return result;
        }

    }
    static class Pair{
        long x,y,z;
        public Pair(long x,long y,long z){
            this.x=x;
            this.y=y;
            this.z=z;
        }
        @Override
        public boolean equals(Object o) {
            if (this == o) return true;
            if (!(o instanceof Pair)) return false;
            Pair key = (Pair) o;
            return x == key.x && y == key.y && z==key.z;
        }
    }
    static class Pair1{
        long x,y;
        public Pair1(long x,long y){
            this.x=x;
            this.y=y;

        }
    }
    static PrintWriter w = new PrintWriter(System.out);
    static long mod=998244353L,mod1=1000000007;

    public static void main(String [] args){
        InputReader sc=new InputReader(System.in);

        int t=sc.ni();
        while(t-->0){
            int n=sc.ni();
            int arr[]=new int[n];
            int dp[][]=new int[n][27];
            int c[]=new int[27];
            HashMap<Integer,Integer> back[]=new HashMap[27];
            for(int i=0;i<27;i++){
                back[i]=new HashMap<>();
            }
            for(int i=0;i<n;i++){
                arr[i]=sc.ni();
                c[arr[i]]++;
                dp[i][arr[i]]++;
                //dp[i][arr[i]]++;
            }
            for(int i=1;i<n;i++){
                for(int j=1;j<27;j++){
                    dp[i][j]+=dp[i-1][j];
                }
            }
            int c1[]=new int[27];
            for(int i=n-1;i>=0;i--){
                c1[arr[i]]++;
                back[arr[i]].put(c1[arr[i]],i);
            }
            int ans=0;
            for(int i=1;i<=26;i++)ans=Math.max(c[i],ans);
            for(int i=0;i<n;i++){
                int fc=dp[i][arr[i]];
                if(back[arr[i]].containsKey(fc)){
                    int in=back[arr[i]].get(fc)-1;
                    if(in<i)continue;
                    int ma=0;
                    for(int k=1;k<=26;k++){
                        ma=Math.max(ma,dp[in][k]-dp[i][k]);
                    }
                    ans=Math.max(ma+fc+fc,ans);
                }

//                int fc=1,bc=0;
//                for(int j=0;j<i;j++){
//                    if(arr[i]==arr[j])fc++;
//                }
//                int j=n-1;
//                while(j>i&&bc<fc){
//                    if(arr[j]==arr[i])bc++;
//                    if(fc==bc)break;
//                    j--;
//                }
//                if(fc==bc){
//                    int ma=0;
//                    int co[]=new int[27];
//                    for(int k=i+1;k<j;k++){
//                        co[arr[k]]++;
//                        ma=Math.max(co[arr[k]],ma);
//                    }
//                    ans=Math.max(ans,fc+bc+ma);
//                }
            }
            w.println(ans);
        }
        w.close();
    }
}


#include<iostream>
#include<map>
using namespace std;
map<int,int>ma;
int main()
{
	int n,m,ans=0,mi=-1;
	cin>>n;
	for(int i=0;i<n;i++)
	{
		ans++;
		cin>>m;
		ma[m]++;
		if(ma[m]==2)ans-=2;
		mi=max(mi,ans);
	}
	mi=max(mi,ans);
	cout<<mi<<endl;
	return 0;
}


#include<iostream>
#include<map>
using namespace std;
map<int,int>ma;
int main()
{
	int n,m,ans=0,mi=-1;
	cin>>n;
	for(int i=0;i<n;i++)
	{
		ans++;
		cin>>m;
		ma[m]++;
		if(ma[m]==2)ans--;
		mi=max(mi,ans);
	}
	cout<<mi<<endl;
	return 0;
}


#pragma comment (linker, "/STACK:64000000")
#include <iostream>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <map>
#include <cmath>
#include <vector>
#include <queue>
#include <iomanip>
#include <set>
#include <stdio.h>
#include <string.h>

using namespace std;

const int N6 = 1e6 + 6;
const int N9 = 1e9 + 7;

typedef unsigned long long ull;
typedef long long ll;
typedef double ld;
typedef pair <int, int> PII;
typedef pair <int, ll> PIl;
typedef pair <ll, int> PlI;
typedef pair <ll, ll> Pll;

#define F first
#define S second
#define pb push_back
#define p push
#define mp make_pair
#define re(x, a) for (__typeof(a) x = 1; x <= a; ++x)
#define reo(x, a) for (__typeof(a) x = 1; x <= a; ++x)
#define rep(x, a) for (__typeof(a) x = 1; x <= a; ++x)
#define erp(x, a) for (__typeof(a) x = 1; x <= a; ++x)
#define repp(x, a) for (__typeof(a) x = 0; x < a; ++x)
#define epo(x, a) for (__typeof(a) x = 1; x <= a; ++x)
#define itn int
#define for1(x, b, a) for (int x = b; x >= a; --x)
#define sz(x) (int)x.size()
#define siz size
#define skip continue
#define gg exit(0)
#define boost ios_base::sync_with_stdio(0),cin.tie(NULL)
#define task "Team"

const unsigned long long N = 2 * 1e5 + 5;
const ll INF = (ll)1e9 + 100;
const ll mod = 1743;
const ll P = 31;

ll n, a[N], ans, mx = 0;

map<int,int>cnt;

int main(){

  // freopen(task".in","r",stdin);freopen(task".out","w",stdout);

  cin >> n;

  for(int i = 1; i <= n * 2; ++i){
    cin >> a[i];
  }

  for(int i = 1; i <= n * 2; ++i){

    if( cnt.count(a[i]) ){
      ans = max( ans, mx );
      --mx;
    }else{
      ++mx;
      cnt[a[i]];
    }

  }

  ans = max( ans, mx );

  cout << ans;

  return 0;
}


#pragma comment (linker, "/STACK:64000000")
#include <iostream>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <map>
#include <cmath>
#include <vector>
#include <queue>
#include <iomanip>
#include <set>
#include <stdio.h>
#include <string.h>

using namespace std;

const int N6 = 1e6 + 6;
const int N9 = 1e9 + 7;

typedef unsigned long long ull;
typedef long long ll;
typedef double ld;
typedef pair <int, int> PII;
typedef pair <int, ll> PIl;
typedef pair <ll, int> PlI;
typedef pair <ll, ll> Pll;

#define F first
#define S second
#define pb push_back
#define p push
#define mp make_pair
#define re(x, a) for (__typeof(a) x = 1; x <= a; ++x)
#define reo(x, a) for (__typeof(a) x = 1; x <= a; ++x)
#define rep(x, a) for (__typeof(a) x = 1; x <= a; ++x)
#define erp(x, a) for (__typeof(a) x = 1; x <= a; ++x)
#define repp(x, a) for (__typeof(a) x = 0; x < a; ++x)
#define epo(x, a) for (__typeof(a) x = 1; x <= a; ++x)
#define itn int
#define for1(x, b, a) for (int x = b; x >= a; --x)
#define sz(x) (int)x.size()
#define siz size
#define skip continue
#define gg exit(0)
#define boost ios_base::sync_with_stdio(0),cin.tie(NULL)
#define task "Team"

const unsigned long long N = 2 * 1e5 + 5;
const ll INF = (ll)1e9 + 100;
const ll mod = 1743;
const ll P = 31;

ll n, a[N], ans, mx = 0;

map<int,int>cnt;

int main(){

  // freopen(task".in","r",stdin);freopen(task".out","w",stdout);

  cin >> n;

  for(int i = 1; i <= n * 2; ++i){
    cin >> a[i];
  }

  for(int i = 1; i <= n * 2; ++i){

    if( cnt.count(a[i]) ){
      ans = max( ans, mx );
      --mx;
    }else{
      ++mx;
      cnt[a[i]];
    }

  }

  cout << ans;

  return 0;
}


#pragma comment (linker, "/STACK:64000000")
#include <iostream>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <map>
#include <cmath>
#include <vector>
#include <queue>
#include <iomanip>
#include <set>
#include <stdio.h>
#include <string.h>

using namespace std;

const int N6 = 1e6 + 6;
const int N9 = 1e9 + 7;

typedef unsigned long long ull;
typedef long long ll;
typedef double ld;
typedef pair <int, int> PII;
typedef pair <int, ll> PIl;
typedef pair <ll, int> PlI;
typedef pair <ll, ll> Pll;

#define F first
#define S second
#define pb push_back
#define p push
#define mp make_pair
#define re(x, a) for (__typeof(a) x = 1; x <= a; ++x)
#define reo(x, a) for (__typeof(a) x = 1; x <= a; ++x)
#define rep(x, a) for (__typeof(a) x = 1; x <= a; ++x)
#define erp(x, a) for (__typeof(a) x = 1; x <= a; ++x)
#define repp(x, a) for (__typeof(a) x = 0; x < a; ++x)
#define epo(x, a) for (__typeof(a) x = 1; x <= a; ++x)
#define itn int
#define for1(x, b, a) for (int x = b; x >= a; --x)
#define sz(x) (int)x.size()
#define siz size
#define skip continue
#define gg exit(0)
#define boost ios_base::sync_with_stdio(0),cin.tie(NULL)
#define task "Team"

const unsigned long long N = 2 * 1e5;
const ll INF = (ll)1e9 + 100;
const ll mod = 1743;
const ll P = 31;

ll n, a[N], ans, mx = 0;

map<int,int>cnt;

int main(){

  // freopen(task".in","r",stdin);freopen(task".out","w",stdout);

  cin >> n;

  for(int i = 1; i <= n * 2; ++i){
    cin >> a[i];
  }

  for(int i = 1; i <= n * 2; ++i){

    if( cnt.count(a[i]) ){
      --mx;
    }else{
      ++mx;
      cnt[a[i]];
    }

    ans = max( ans, mx );

  }

  cout << ans;

  return 0;
}


#pragma comment (linker, "/STACK:64000000")
#include <iostream>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <map>
#include <cmath>
#include <vector>
#include <queue>
#include <iomanip>
#include <set>
#include <stdio.h>
#include <string.h>

using namespace std;

const int N6 = 1e6 + 6;
const int N9 = 1e9 + 7;

typedef unsigned long long ull;
typedef long long ll;
typedef double ld;
typedef pair <int, int> PII;
typedef pair <int, ll> PIl;
typedef pair <ll, int> PlI;
typedef pair <ll, ll> Pll;

#define F first
#define S second
#define pb push_back
#define p push
#define mp make_pair
#define re(x, a) for (__typeof(a) x = 1; x <= a; ++x)
#define reo(x, a) for (__typeof(a) x = 1; x <= a; ++x)
#define rep(x, a) for (__typeof(a) x = 1; x <= a; ++x)
#define erp(x, a) for (__typeof(a) x = 1; x <= a; ++x)
#define repp(x, a) for (__typeof(a) x = 0; x < a; ++x)
#define epo(x, a) for (__typeof(a) x = 1; x <= a; ++x)
#define itn int
#define for1(x, b, a) for (int x = b; x >= a; --x)
#define sz(x) (int)x.size()
#define siz size
#define skip continue
#define gg exit(0)
#define boost ios_base::sync_with_stdio(0),cin.tie(NULL)
#define task "Team"

const unsigned long long N = 4 * 1e5;
const ll INF = (ll)1e9 + 100;
const ll mod = 1743;
const ll P = 31;

ll n, a[N], ans, mx = 0;

map<int,int>cnt;

int main(){

  // freopen(task".in","r",stdin);freopen(task".out","w",stdout);

  cin >> n;

  for(int i = 1; i <= n * 2; ++i){
    cin >> a[i];
  }

  for(int i = 1; i <= n * 2; ++i){

    if( cnt.count(a[i]) ){
      --mx;
    }else{
      ++mx;
      cnt[a[i]];
    }

    ans = max( ans, mx );

  }

  cout << ans;

  return 0;
}


#pragma comment (linker, "/STACK:64000000")
#include <iostream>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <map>
#include <cmath>
#include <vector>
#include <queue>
#include <iomanip>
#include <set>
#include <stdio.h>
#include <string.h>

using namespace std;

const int N6 = 1e6 + 6;
const int N9 = 1e9 + 7;

typedef unsigned long long ull;
typedef long long ll;
typedef double ld;
typedef pair <int, int> PII;
typedef pair <int, ll> PIl;
typedef pair <ll, int> PlI;
typedef pair <ll, ll> Pll;

#define F first
#define S second
#define pb push_back
#define p push
#define mp make_pair
#define re(x, a) for (__typeof(a) x = 1; x <= a; ++x)
#define reo(x, a) for (__typeof(a) x = 1; x <= a; ++x)
#define rep(x, a) for (__typeof(a) x = 1; x <= a; ++x)
#define erp(x, a) for (__typeof(a) x = 1; x <= a; ++x)
#define repp(x, a) for (__typeof(a) x = 0; x < a; ++x)
#define epo(x, a) for (__typeof(a) x = 1; x <= a; ++x)
#define itn int
#define for1(x, b, a) for (int x = b; x >= a; --x)
#define sz(x) (int)x.size()
#define siz size
#define skip continue
#define gg exit(0)
#define boost ios_base::sync_with_stdio(0),cin.tie(NULL)
#define task "Team"

const unsigned long long N = 2 * 1e5;
const ll INF = (ll)1e9 + 100;
const ll mod = 1743;
const ll P = 31;

ll n, a[N], ans, mx = 0;

map<int,int>cnt;

int main(){

  // freopen(task".in","r",stdin);freopen(task".out","w",stdout);

  cin >> n;

  for(int i = 1; i <= n * 2; ++i){
    cin >> a[i];
  }

  for(int i = 1; i <= n * 2; ++i){

    if( cnt.count(a[i]) ){
      ans = max( ans, mx );
      --mx;
    }else{
      ++mx;
      cnt[a[i]];
    }

  }
ans = max( ans, mx );
  cout << ans;

  return 0;
}


#pragma comment (linker, "/STACK:64000000")
#include <iostream>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <map>
#include <cmath>
#include <vector>
#include <queue>
#include <iomanip>
#include <set>
#include <stdio.h>
#include <string.h>

using namespace std;

const int N6 = 1e6 + 6;
const int N9 = 1e9 + 7;

typedef unsigned long long ull;
typedef long long ll;
typedef double ld;
typedef pair <int, int> PII;
typedef pair <int, ll> PIl;
typedef pair <ll, int> PlI;
typedef pair <ll, ll> Pll;

#define F first
#define S second
#define pb push_back
#define p push
#define mp make_pair
#define re(x, a) for (__typeof(a) x = 1; x <= a; ++x)
#define reo(x, a) for (__typeof(a) x = 1; x <= a; ++x)
#define rep(x, a) for (__typeof(a) x = 1; x <= a; ++x)
#define erp(x, a) for (__typeof(a) x = 1; x <= a; ++x)
#define repp(x, a) for (__typeof(a) x = 0; x < a; ++x)
#define epo(x, a) for (__typeof(a) x = 1; x <= a; ++x)
#define itn int
#define for1(x, b, a) for (int x = b; x >= a; --x)
#define sz(x) (int)x.size()
#define siz size
#define skip continue
#define gg exit(0)
#define boost ios_base::sync_with_stdio(0),cin.tie(NULL)
#define task "Team"

const unsigned long long N = 2 * 1e5;
const ll INF = (ll)1e9 + 100;
const ll mod = 1743;
const ll P = 31;

ll n, a[N], ans, mx = 0;

map<int,int>cnt;

int main(){

  // freopen(task".in","r",stdin);freopen(task".out","w",stdout);

  cin >> n;

  for(int i = 1; i <= n * 2; ++i){
    cin >> a[i];
  }

  for(int i = 1; i <= n * 2; ++i){

    if( cnt.count(a[i]) ){
      ans = max( ans, mx );
      --mx;
    }else{
      ++mx;
      cnt[a[i]];
    }

  }

  cout << ans;

  return 0;
}


#include<iostream>
using namespace std;
int main()
{
	int n;
	cin>>n;
	int A[100000] = { };
	int count = 0, m = 0;
	for(int i = 0; i < n; i++){
		int x;
		cin>>x;
		if(A[x] == 0){
			A[x] = 1;
			count += 1;
		}
		else if(A[x] == 1){
			count -= 1;
		}
		m = max(m, count);
	}
	cout<<m<<endl;
	return 0;
}


#include<iostream>
#include<cstdlib>
#include<vector>
#include<utility>
#include<map>
#include<vector>
#include<set>
using namespace std;

typedef vector< int >  vi;
typedef vector< vi> vvi;
typedef pair<int, int> ii;

#define pb push_back
#define sz(c) (c).size()
#define all(c) ((c).begin(), (c).end())
#define tr(c, i) for(auto it = (c).begin(); it != (c).end(); it++)
#define present(c, x) ((c).find(x) != (c).end())
#define cpresent(c, x) (find(all(c)) != (c).end())

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);

	int n;
	cin>>n;
	set<int>s;
	int m = 0;
	for(int i = 0; i < 2*n; i++){
		int x;
		cin>>x;
		if(present(s, x))
			s.erase(x);
		else
			s.insert(x);
		m = max(m, int(sz(s)));
	}
	cout<<m<<"\n";
	return 0;
}


#include<iostream>
#include<vector>
#include<utility>
#include<map>
#include<vector>
#include<set>
using namespace std;

typedef vector< int >  vi;
typedef vector< vi> vvi;
typedef pair<int, int> ii;

#define pb push_back
#define sz(c) (c).size()
#define all(c) ((c).begin(), (c).end())
#define tr(c, i) for(auto it = (c).begin(); it != (c).end(); it++)
#define present(c, x) ((c).find(x) != (c).end())
#define cpresent(c, x) (find(all(c)) != (c).end())

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);

	int n;
	cin>>n;
	set<int>s;
	int m = 0;
	while(2*n--){
		int x;
		cin>>x;
		if(present(s, x))
			s.erase(x);
		else
			s.insert(x);
		m = max(m, int(sz(s)));
	}
	cout<<m<<"\n";
	return 0;
}


#include<iostream>
using namespace std;
int main()
{
	int n;
	cin>>n;
	int A[1000001] = { };
	int count = 0, m = 0;
	for(int i = 0; i < 2*n; i++){
		int x;
		cin>>x;
		if(A[x] == 0){
			A[x] = 1;
			count++;
		}
		else if(A[x] == 1){
			A[x] = 0;
			count--;
		}
		m = max(m, count);
	}
	cout<<m<<"\n";
	return 0;
}


#include <iostream>
#include <map>
using namespace std;
int a[100005],i,n,cnt,res,x;
map<int,int>mp;
main() {
 cin >> n;
 for (i = 0; i < n; i ++) {
 	cin >> x;
	 if(mp[x] == 0) {
	 	cnt ++;
	 	res = max(cnt,res);
	 	mp[x] ++;
	 }	else {
	 cnt=0;}
 }
 cout << res;
}


#include <iostream>
#include <map>
using namespace std;
int a[300005],i,n,cnt,res = 0,x;
map<int,int>mp;
main() {
	cin >> n;
	for (i = 0; i < 2*n; i ++) {
		cin >> a[i];
	}
	for (i = 0; i < 2*n; i ++) {
		if(mp[a[i]] == 0) {
			cnt ++;
			mp[a[i]] = 1;
		}else {
			res = max(res, cnt);
			cnt = 1;
		}
		mp[a[i]] = 1;
	}
	cout << res;
}


#include <iostream>
#include <map>
using namespace std;
int a[100005],i,n,cnt,res,x;
map<int,int>mp;
main() {
 cin >> n;
 for (i = 0; i <2* n; i ++) {
 	cin >> x;
	 if(mp[x] == 0) {
	 	cnt ++;
	 	res = max(cnt,res);
	 	mp[x] ++;
	 }	else {
	 cnt=0;}
 }
 cout << res;
}


#include <iostream>
#include <map>
using namespace std;
int a[300005],i,n,cnt,res = 0,x;
map<int,int>mp;
main() {
	cin >> n;
	for (i = 0; i < 2*n; i ++) {
		cin >> a[i];
	}
	for (i = 0; i < 2*n; i ++) {
		if(mp[a[i]] == 0) {
			cnt ++;
			res = max(cnt, res);
		}else {
			cnt --;
		}
		mp[a[i]] = 1;
	}
	cout << res;
}


#include <iostream>
#include <map>
using namespace std;
int a[100005],i,n,cnt,res = 0,x;
map<int,int>mp;
main() {
	cin >> n;
	for (i = 0; i < 2*n; i ++) {
		cin >> a[i];
	}
	for (i = 0; i < 2*n; i ++) {
		if(mp[a[i]] == 0) {
			cnt ++;
			mp[a[i]] = 1;
		}else {
			res = max(res, cnt);
			cnt = 1;
		}
		mp[a[i]] = 1;
	}
	cout << res;
}


#include <iostream>
#include <map>
using namespace std;
int a[300005],i,n,cnt,res = 0,x;
map<int,int>mp;
main() {
	cin >> n;
	for (i = 0; i < 2*n; i ++) {
		cin >> a[i];
	}
	for (i = 0; i < 2*n; i ++) {
		if(mp[a[i]] == 0) {
			cnt ++;
		}else {
			cnt --;
		}
		mp[a[i]] = 1;
	}
	cout << res;
}


#include <iostream>
#include <map>
using namespace std;
int a[100005],i,n,cnt,res;
map<int,int>mp;
main() {
 cin >> n;
 for (i = 0; i < n; i ++) {
 	cin >> a[i];
 }
 for (i = 0; i < n-1; i ++) {
 	if(a[i] != a[i + 1] && mp[a[i]] == 0) {
 		cnt ++;
 		mp[a[i]] = 1;
 		res = max(res,cnt);
	 }
	 else {cout << cnt;

	 	mp.clear();
	 	cnt=0;
	 }
 }
 cout << res + 1;
}


#include <iostream>
#include <map>
using namespace std;
int a[100005],i,n,cnt,res;
map<int,int>mp;
main() {
 cin >> n;
 for (i = 0; i < n; i ++) {
 	cin >> a[i];
 }
 for (i = 0; i < n-1; i ++) {
 	if(a[i] != a[i + 1] && mp[a[i]] == 0) {
 		cnt ++;
 		mp[a[i]] = 1;
 		res = max(res,cnt);
	 }
	 else {

	 	mp.clear();
	 	cnt=0;
	 }
 }
 cout << res + 1;
}


#include <iostream>
#include <map>
using namespace std;
int a[100005],i,n,cnt,res;
map<int,int>mp;
main() {
 cin >> n;
 for (i = 0; i < n; i ++) {
 	cin >> a[i];
 }
 for (i = 1; i < n; i ++) {
 	if(a[i] != a[i - 1] && mp[a[i]] == 0) {
 		cnt ++;
 		mp[a[i]] = 1;
	 }
	 else {
	 	res = max(res,cnt);
	 	mp.clear();
	 	cnt=0;
	 }
 }
 cout << res + 1;
}


#include <iostream>
#include <map>
using namespace std;
int a[100005],i,n,cnt,res,x;
map<int,int>mp;
main() {
 cin >> n;
 for (i = 0; i < n; i ++) {
 	cin >> x;
	 if(mp[x] == 0) {
	 	cnt ++;
	 	res = max(cnt,res);
	 }	else {
	 cnt=0;}
 }
 cout << res;
}


#include <iostream>
#include <map>
using namespace std;
int a[100005],i,n,cnt,res,x;
map<int,int>mp;
main() {
 cin >> n;
 for (i = 0; i <2 * n; i ++) {
 	cin >> x;
	 if(mp[x] == 0) {
	 	cnt ++;
	 	res = max(cnt,res);
	 	mp[x] ++;
	 }	else {
	 cnt=0; mp.clear();}
 }
 cout << res;
}


#include <iostream>
#include <map>
using namespace std;
int a[100005],i,n,cnt,res;
map<int,int>mp;
main() {
 cin >> n;
 for (i = 0; i <2* n; i ++) {
 	cin >> a[i];
 }
 for (i = 1; i <2* n; i ++) {
 	if(a[i] != a[i - 1] && mp[a[i]] == 0) {
 		cnt ++;
 		mp[a[i]] = 1;
	 }
	 else {
	 	res = max(res,cnt);
	 	mp.clear();
	 	cnt=0;
	 }
 }
 cout << res + 1;
}


#include<bits/stdc++.h>

using namespace std;

#define rd freopen("in.txt", "r", stdin)
#define wr freopen("out.txt", "w", stdout)
#define ios ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define FOR(n) for(int i=0;i<n;i++)

const int N=100010;
bool A[N];

int main() {
    ios;
    int n,tmp,r,c=0;
    cin >> n;
    for(int i=0;i<2*n;i++) {
    	cin >> tmp;
    	if(A[tmp])
    		c--;
    	else c++;
    	r=max(r,c);
		A[tmp]^=1;
    }
    cout << r << '\n';
    return 0;
}


#include<bits/stdc++.h>

using namespace std;

#define rd freopen("in.txt", "r", stdin)
#define wr freopen("out.txt", "w", stdout)
#define ios ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define FOR(n) for(int i=0;i<n;i++)

const int N=100010;
bool A[N];

int main() {
    ios;
    int n,tmp,r;
    cin >> n;
    for(int i=0;i<2*n;i++) {
    	cin >> tmp;
    	r=max(r,(int)A[tmp]);
		A[tmp]^=1;
    }
    cout << r << '\n';
    return 0;
}


#include<bits/stdc++.h>

using namespace std;

const int N=100010;
bool A[N];

int main() {
    int n,tmp,r,c=0;
    cin >> n;
    for(int i=0;i<2*n;i++) {
    	cin >> tmp;
    	if(A[tmp])
    		c--;
    	else c++;
    	r=max(r,c);
		A[tmp]^=1;
    }
    cout << r << '\n';
    return 0;
}


#include<bits/stdc++.h>

using namespace std;

const int N=100010;
bool A[N];

int main() {
    int n,tmp,r,c=0;
    cin >> n;
    for(int i=0;i<2*n;i++) {
    	cin >> tmp;
    	if(A[tmp])
    		c++;
    	else c--;
    	r=max(r,c);
		A[tmp]^=1;
    }
    cout << r << '\n';
    return 0;
}


 #include <bits/stdc++.h>

using namespace std;
int a[100000];
int u[100005];
int main()
{
    int n;
    cin>>n;
    int k=0, ans=0;
    for (int i=0;i<2*n;i++){
        cin>>a[i];
    }
    for (int i=0;i<n;i++){
        u[a[i]]++;
        if (u[a[i]]==1){
            k++;
        }

        else {

            u[a[i]]=0;
            k--;
        }
        ans=max(k,ans);
    }
    cout<<ans;
    return 0;
}


 #include <bits/stdc++.h>

using namespace std;
long long a[100000];
long long u[100005];
int main()
{
    long long n;
    cin>>n;
    long long k=0, ans=0;
    for (int i=0;i<2*n;i++){
        cin>>a[i];
    }
    for (int i=0;i<n;i++){
        u[a[i]]++;
        if (u[a[i]]==1){
            k++;
        }

        else {

            u[a[i]]=0;
            k--;
        }
        ans=max(k,ans);
    }
    cout<<ans;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
int a[110];
int u[100005];
int main()
{
    int n;
    cin>>n;
    int k=0, ans=1;
    for (int i=0;i<2*n;i++){
        cin>>a[i];
    }
    for (int i=0;i<n;i++){
        u[a[i]]++;
        if (u[a[i]]==1){
            k++;
        }
        else {
            ans=max(k,ans);
            u[a[i]]=0;
        }
    }
    cout<<ans;
    return 0;
}


 #include <bits/stdc++.h>

using namespace std;
long long a[200005];
long long u[200005];
int main()
{
    long long n;
    cin>>n;
    long long k=0, ans=0;
    for (int i=0;i<2*n;i++){
        cin>>a[i];
    }
    for (int i=0;i<2*n;i++){
        u[a[i]]++;
        if (u[a[i]]==1){
            k++;
        }

        else {

            u[a[i]]=0;
            k--;
        }
        ans=max(k,ans);
    }
    cout<<ans;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
int a[110];
int u[100005];
int main()
{
    int n;
    cin>>n;
    int k=0, ans=1;
    for (int i=0;i<n;i++){
        cin>>a[i];
    }
    for (int i=0;i<n;i++){
        u[a[i]]++;
        if (u[a[i]]==1){
            k++;
        }
        else {
            ans=max(k,ans);
            u[a[i]]=0;
        }
    }
    cout<<ans;
    return 0;
}


 #include <bits/stdc++.h>

using namespace std;
int a[110];
int u[100005];
int main()
{
    int n;
    cin>>n;
    int k=0, ans=0;
    for (int i=0;i<2*n;i++){
        cin>>a[i];
    }
    for (int i=0;i<n;i++){
        u[a[i]]++;
        if (u[a[i]]==1){
            k++;
        }

        else {

            u[a[i]]=0;
            k--;
        }
        ans=max(k,ans);
    }
    cout<<ans;
    return 0;
}


 #include <bits/stdc++.h>

using namespace std;
int a[110];
int u[100005];
int main()
{
    int n;
    cin>>n;
    int k=0, ans=1;
    for (int i=0;i<2*n;i++){
        cin>>a[i];
    }
    for (int i=0;i<n;i++){
        u[a[i]]++;
        if (u[a[i]]==1){
            k++;
        }
        else {
            ans=max(k,ans);
            u[a[i]]=0;
            k--;
        }
    }
    cout<<ans;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
int a[110];
int main()
{
    int n;
    cin>>n;
    int k=1, ans=1;
    for (int i=0;i<n;i++){
        cin>>a[i];
    }
    for (int i=0;i<n;i++){
        if (a[i]!=a[i+1]){
            k++;
        }
        else{
            ans=max(k,ans);
            k=k-1;
        }
    }
    cout<<ans;
    return 0;
}


#include<iostream>
#include<stdlib.h>
using namespace std;
int main(){
int s;
cin>>s;
long int c=0;int mc=0;
int a[2*s];
int b[2*s];
for(int i=0;i<(2*s);i++)
{
	cin>>a[i];
	b[i]=0;
 }
for(int i=0;i<(2*s);i++){
 b[a[i]]++;c++;

 if(b[a[i]]==2)
{

	c--;
if(c>mc){mc=c;c--;}
else
c--;

 }
}
cout<<mc;
}


#include<iostream>
#include<stdlib.h>
using namespace std;
int main(){
long long int s;
cin>>s;
long long int c=0;int mc=0;
int a[2*s];
int b[2*s];
for(int i=0;i<(2*s);i++)
{
	cin>>a[i];
	b[i]=0;
 }
for(int i=0;i<(2*s);i++){
 b[a[i]]++;c++;

 if(b[a[i]]==2)
{
  if(c>mc)
    {
	;mc=c-1;c=0;
	}
	else{
	c=0;
	}
 }
}
cout<<mc;
}


#include<iostream>
#include<stdlib.h>
using namespace std;
int main(){
int s;
cin>>s;
long int c=0;int mc=0;
int a[2*s];
int b[2*s];
for(int i=0;i<(2*s);i++)
{
	cin>>a[i];
	b[i]=0;
 }
for(int i=0;i<(2*s);i++){
 b[a[i]]++;c++;

 if(b[a[i]]==2)
{

	c--;
if(c>mc){mc=c;c--;}

 }
}
cout<<mc;
}


#include<iostream>
#include<stdlib.h>
using namespace std;
int main(){
int s;
cin>>s;
long int c=0;int mc=0;
int a[2*s];
int b[2*s];
for(int i=0;i<(2*s);i++)
{
	cin>>a[i];
	b[i]=0;
 }
for(int i=0;i<(2*s);i++){
 b[a[i]]++;c++;

 if(b[a[i]]==2)
 {
  c--;
	if(c>mc)
 	{
   	mc=c;c--;
  	}
	else
	c--;
  }
                     }
}
cout<<mc;
}


#include<iostream>
#include<stdlib.h>
using namespace std;
int main(){
int s;
cin>>s;
long int c=0;int mc=0;
int a[2*s];
int b[2*s];
for(int i=0;i<(2*s);i++)
{
	cin>>a[i];
	b[i]=0;
 }
for(int i=0;i<(2*s);i++){
 b[a[i]]++;c++;
  cout<<"C is"<<c<<endl;
 if(b[a[i]]==2)
{

	c--;
if(c>mc){mc=c;c--;cout<<"Mc is"<<mc;}

 }
}
cout<<"the max no is"<<mc;
}


#include<iostream>
#include<stdlib.h>
using namespace std;
int main(){
int s;
cin>>s;
long int c=0;int mc=0;
int a[2*s];
int b[2*s];
for(int i=0;i<(2*s);i++)
{
	cin>>a[i];
	b[i]=0;
 }
for(int i=0;i<(2*s);i++){
 b[a[i]]++;c++;

 if(b[a[i]]==2)
{
  if(c>mc)
    {
	;mc=c-1;c=0;
	}
	else{
	c=0;
	}
 }
}
cout<<mc;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
bool arr[10001];
int main (){
	int n;
	cin >>n;
	int a;
	int maxl=-1,f=0;
	for (int i=1;i<=2*n;i++){
		cin >>a;
		if (arr[2*a-1]==1){
			arr[2*a]=1;
		}
		else {
			arr[2*a-1]=1;
		}
		if (arr[2*a-1]!=arr[2*a]){
			f++;
		}
		else if (arr[2*a-1]==arr[2*a]){
			f--;
		}
		maxl = max(maxl,f);
	}
	cout <<maxl;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
pair <bool,bool> arr[10001];
int main (){
	int n;
	cin >>n;
	int f=0,maxl=0;
	for (int i=1;i<=2*n;i++){
		int a;
		cin >>a;
		if (arr[a].first == 1){
			arr[a].second =1;
		}
		else {
			arr[a].first = 1;
		}
		if (arr[a].first == arr[a].second && arr[a].second == 1){
			f--;
		}
		else {
			f++;
		}
		maxl = max(maxl,f);
	}
	cout <<maxl;
	return 0;
}