Victor wants to become "Mr. Perfectly Fine". For that, he needs to acquire a certain set of skills. More precisely, he has 2 skills he needs to acquire. Victor has n books. Reading book i takes him mi minutes and will give him some (possibly none) of the required two skills, represented by a binary string of .length 2. What is the minimum amount of time required so that Victor acquires all of the two skills? Input The input consists of multiple test cases. The first line contains an integer t the number of test cases. The description of the test cases follows. The first line of each test case contains an integer n the number of books available. Then n lines follow. Line i contains a positive integer mi and a binary string of length 2, where si1=1 if reading book i acquires Victor skill 1, and si1=0 otherwise, and si2=1 if reading book i acquires Victor skill 2, and si2=0 otherwise. It is guaranteed that the sum of n over all test cases doesn't exceed 2⋅10^5. Output For each test case, output a single integer denoting the minimum amount of minutes required for Victor to obtain both needed skills and −1 in case it's impossible to obtain the two skills after reading any amount of books.
n=int(input()) a=[] for i in range(n): a.append(list(map(int,input().split()))) k=0 for j in range(len(a)): if a[j][0]==0: k=k+1 if k==len(a): print(-1) else: f=0 s=0 for i in range(len(a)): if a[i][1][0]=='1': f=1 if a[i][1][1]=='1': s=1 if f==s==1: k=[] for i in range(len(a)): k.append(a[i][0]) print(min(k)) else: print(-1)