#include <iostream>
#include <algorithm>
#include <string>
#include <set>
#include <map>
#include <utility>
#include <queue>
#include <stack>
#include <vector>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
using namespace std;
struct type
{
char name[30];
int num;
}a[1005];
const int MAX_PRIME = 1 << 16;
# define PRIME_NUM 35000
int Primes[PRIME_NUM + 10] ;
bool PrimeBuffer[MAX_PRIME];
int _Count = 0;
int GetPrimes ()
{
int i, j ;
for (i = 2 ; i < MAX_PRIME ; i++)
{
if (PrimeBuffer[i] == 0)
Primes[_Count++] = i ;
for (j = 0 ; j < _Count && i * Primes[j] <= MAX_PRIME ; j++)
{
PrimeBuffer[i * Primes[j]] = 1 ;
if (i % Primes[j] == 0) break ;
}
}
free (PrimeBuffer) ;
return _Count ;
}
inline bool scan_d(int &num) //整数输入
{
char in;bool IsN=false;
in=getchar();
if(in==EOF) return false;
while(in!='-'&&(in<'0'||in>'9')) in=getchar();
if(in=='-'){ IsN=true;num=0;}
else num=in-'0';
while(in=getchar(),in>='0'&&in<='9'){
num*=10,num+=in-'0';
}
if(IsN) num=-num;
return true;
}
int main ()
{
int T;
GetPrimes ();
scan_d(T);
while ( T -- ) {
int N;
scan_d( N );
int ma = -1;
char mi[30] = "{";
for ( int i = 0 ; i < N ; ++ i ) {
scanf ( "%s",a[i].name);
scan_d( a[i].num );
int cnt = 0;
for ( int j = 0 ; j < _Count && a[i].num > 1 ; ++ j ) {
if ( a[i].num%Primes[j]==0 ) {
while(a[i].num%Primes[j]==0)
{
a[i].num /= Primes[j];
}
cnt++;
}
}
if ( cnt == 0 ) cnt = 1; // 没加这句也能A 说明没有 1 和 超过1<<16的素数
if ( ma < cnt ) { ma = cnt; strcpy ( mi, a[i].name ); }
else if ( ma == cnt ) {
if ( strcmp ( a[i].name, mi ) < 0 )
strcpy ( mi, a[i].name );
}
}
puts(mi);
}
return 0;
}