
class Solution:
    # Function for finding maximum AND value.
    # maxAND() takes the array elements and N (size of the array) as input parameters and returns the maximum AND value generated by any pair in the array. 
    def maxAND(self, arr,N):
        pattern = 0
        RES = 0
        m = len(bin(max(arr))) - 3 
        
        #loop from msb to lsb
        for i in range(-m, 1, 1):
        # or can use 'for i in range(16,-1,-1):', iterating over total of 16 bits from MSB to LSB
            pattern = RES|(1 << abs(i))
            c = 0
            pattern += 1 << abs(i)
            
            #loop from array elements 1 to N
            for j in range(N):
                
                if( pattern & arr[j] == pattern ):
                    c += 1
                    if(c >= 2):
                        RES |= 1 << abs(i)
                        break
                    
                    
        return RES   
       
import math

def main():
  T = int(input())
  while(T > 0):
    n = int(input))
    
    arr = [int(x) for x in input().strip().split()]
    obj = Solution()
    print(obj.maxAND(arr, n))
    T -= 1

if __name__ == "__main__":
  main()
