import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Hashtable;
import java.util.Vector;

public class Main {

    public static void main(String[] args) throws NumberFormatException, IOException {
        BufferedReader in=new BufferedReader(new InputStreamReader(System.in));
        PrintWriter out=new PrintWriter(System.out);
        int n=Integer.parseInt(in.readLine());
        Hashtable<String, Integer> hash=new Hashtable<String, Integer>();
        String[] names=new String[n];
        int[] scores=new int[n];
        int max=Integer.MIN_VALUE;
        String maxName=new String();
        for(int i=0; i<n; i++){
            String[] cur=in.readLine().split(" ");
            String name=cur[0];
            Integer score=Integer.parseInt(cur[1]);
            names[i]=name;
            scores[i]=score;
            Integer oldScore=hash.get(name);
            Integer resScore=0;
            if(oldScore==null){
                resScore=score;
            }
            else{
                resScore=oldScore+score;
            }
            hash.put(name, resScore);

        }
        Collection<Integer> vals=hash.values();
        max=Collections.max(vals);
        hash.clear();
        for(int i=0; i<n; i++){
            String name=names[i];
            Integer score=scores[i];
            Integer oldScore=hash.get(name);
            Integer resScore=0;
            if(oldScore==null){
                resScore=score;
            }
            else{
                resScore=oldScore+score;
            }
            hash.put(name, resScore);
            if(resScore>=max){
                maxName=name;
                break;
            }
        }
        if(maxName.equals("ys")) out.println(max);
        out.println(maxName);
        out.close();
    }

}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Hashtable;
import java.util.Vector;

public class Main {

    public static void main(String[] args) throws NumberFormatException, IOException {
        BufferedReader in=new BufferedReader(new InputStreamReader(System.in));
        PrintWriter out=new PrintWriter(System.out);
        int n=Integer.parseInt(in.readLine());
        Hashtable<String, Integer> hash=new Hashtable<String, Integer>();
        String[] names=new String[n];
        int[] scores=new int[n];
        int max=Integer.MIN_VALUE;
        String maxName=new String();
        for(int i=0; i<n; i++){
            String[] cur=in.readLine().split(" ");
            String name=cur[0];
            Integer score=Integer.parseInt(cur[1]);
            names[i]=name;
            scores[i]=score;
            Integer oldScore=hash.get(name);
            Integer resScore=0;
            if(oldScore==null){
                resScore=score;
            }
            else{
                resScore=oldScore+score;
            }
            hash.put(name, resScore);

        }
        Collection<Integer> vals=hash.values();
        max=Collections.max(vals);
        hash.clear();
        for(int i=0; i<n; i++){
            String name=names[i];
            Integer score=scores[i];
            Integer oldScore=hash.get(name);
            Integer resScore=0;
            if(oldScore==null){
                resScore=score;
            }
            else{
                resScore=oldScore+score;
            }
            hash.put(name, resScore);
            if(resScore>=max){
                maxName=name;
                break;
            }
        }
        if(maxName.equals("ys")) {out.println(max);
        out.println(hash.get("gczuitwphlv"));
        }
        out.println(maxName);
        out.close();
    }

}


import java.io.*;
import java.util.*;
public class A2 {
	public static void main(String[] args) throws IOException	{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] name = new String[1000];
		int[] score = new int[1000];
		int best = -1000000000;
		String win = "";
		int n = Integer.parseInt(br.readLine());
		outer: for(int q = 0; q < n; q++)		{
			StringTokenizer st = new StringTokenizer(br.readLine());
			String curr = st.nextToken();
			int num = Integer.parseInt(st.nextToken());
			int i = 0;
			for(i = 0; i < name.length; i++)			{
				if(name[i] == null)
					break;
				if(name[i].equals(curr))	{
					score[i] += num;
					if(score[i] > best)		{
						best = score[i];
						win = name[i];
					}
					continue outer;
				}
				name[i] = curr;
				score[i] = num;
				if(score[i] > best)		{
					best = score[i];
					win = name[i];
					continue outer;
				}
			}
		}
		System.out.println(win);
	}
}


import java.io.*;
import java.util.*;
public class A2 {
	public static void main(String[] args) throws IOException	{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		HashMap<String, Integer> map = new HashMap<String, Integer>();
		int n = Integer.parseInt(br.readLine());
		while(n-- > 0)	{
			StringTokenizer st = new StringTokenizer(br.readLine());
			String name = st.nextToken();
			int add = Integer.parseInt(st.nextToken());
			if(map.containsKey(name))		{
				int val = map.get(name);
				val += add;
				map.put(name, val);
			}
			else	{
				map.put(name, add);
			}
		}
		int worst = -1000000000;
		String name = "";
		for(String win: map.keySet())
			if(map.get(win) > worst)		{
				name = win;
				worst = map.get(win);
			}
		System.out.println(name);
	}
}


import java.io.*;
import java.util.*;
public class A2 {
	public static void main(String[] args) throws IOException	{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(br.readLine());
		String[] inputStr = new String[n];
		int[] inputInt = new int[n];
		for(int i = 0; i < n; i++)		{
			StringTokenizer st = new StringTokenizer(br.readLine());
			inputStr[i] = st.nextToken();
			inputInt[i] = Integer.parseInt(st.nextToken());
		}
		String[] name = new String[n];
		int[] score = new int[n];
		Arrays.fill(score, -1000000000);
		outer: for(int qq = 0; qq < n; qq++)		{
			String nameIn = inputStr[qq];
			int scoreIn = inputInt[qq];
			int i = 0;
			for(i = 0; i < n; i++)		{
				if(name[i] == null)
					break;
				if(name[i].equals(nameIn))	{
					score[i] += scoreIn;
					continue outer;
				}
			}
			name[i] = nameIn;
			score[i] = scoreIn;
		}
		int maxScore = -1000000000;
		for(int x: score)	{
			maxScore = Math.max(maxScore, x);
		}
		Set<String> winner = new HashSet<String>();
		for(int i = 0; i < n; i++)
			if(score[i] == maxScore && name[i] != null)
				winner.add(name[i]);
		name = new String[n];
		score = new int[n];
		Arrays.fill(score, -1000000000);
		outer: for(int qq = 0; qq < n; qq++)		{
			String nameIn = inputStr[qq];
			int scoreIn = inputInt[qq];
			int i = 0;
			for(i = 0; i < n; i++)		{
				if(name[i] == null)
					break;
				if(name[i].equals(nameIn))	{
					score[i] += scoreIn;
					if(score[i] >= maxScore && winner.contains(name[i]))		{
						System.out.println(name[i]);
						return;
					}
					continue outer;
				}
			}
			name[i] = nameIn;
			score[i] = scoreIn;
			if(score[i] >= maxScore && winner.contains(name[i]))		{
				System.out.println(name[i]);
				return;
			}
		}
	}
}


import java.io.*;
import java.util.*;
public class A2 {
	public static void main(String[] args) throws IOException	{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] name = new String[1000];
		int[] score = new int[1000];
		int best = -1000000000;
		String win = "";
		int n = Integer.parseInt(br.readLine());
		outer: for(int q = 0; q < n; q++)		{
			StringTokenizer st = new StringTokenizer(br.readLine());
			String curr = st.nextToken();
			int num = Integer.parseInt(st.nextToken());
			int i = 0;
			for(i = 0; i < name.length; i++)			{
				if(name[i] == null)
					break;
				if(name[i].equals(curr))	{
					score[i] += num;
					if(score[i] > best)		{
						best = score[i];
						win = name[i];
					}
					continue outer;
				}
				name[i] = curr;
				score[i] = num;
				if(score[i] > best)		{
					best = score[i];
					win = name[i];
					continue outer;
				}
			}
		}
	}
}


import java.io.*;
import java.util.*;
public class A2 {
	public static void main(String[] args) throws IOException	{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		HashMap<String, Integer> map = new HashMap<String, Integer>();
		int n = Integer.parseInt(br.readLine());
		while(n-- > 0)	{
			StringTokenizer st = new StringTokenizer(br.readLine());
			String name = st.nextToken();
			int add = Integer.parseInt(st.nextToken());
			if(map.containsKey(name))		{
				int val = map.get(name);
				val += add;
				map.put(name, val);
			}
			else	{
				map.put(name, val)''
			}
		}
		int worst = -1000000000;
		String name = "";
		for(String win: map.keySet())
			if(map.get(win) > worst)		{
				name = win;
				worst = map.get(win);
			}
		System.out.println(name);
	}
}


import java.io.*;
import java.util.*;
public class A2 {
	public static void main(String[] args) throws IOException	{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(br.readLine());
		String[] inputStr = new String[n];
		int[] inputInt = new int[n];
		for(int i = 0; i < n; i++)		{
			StringTokenizer st = new StringTokenizer(br.readLine());
			inputStr[i] = st.nextToken();
			inputInt[i] = Integer.parseInt(st.nextToken());
		}
		String[] name = new String[n];
		int[] score = new int[n];
		Arrays.fill(score, -1000000000);
		outer: for(int qq = 0; qq < n; qq++)		{
			String nameIn = inputStr[qq];
			int scoreIn = inputInt[qq];
			int i = 0;
			for(i = 0; i < n; i++)		{
				if(name[i] == null)
					break;
				if(name[i].equals(nameIn))	{
					score[i] += scoreIn;
					continue outer;
				}
			}
			name[i] = nameIn;
			score[i] = scoreIn;
		}
		int maxScore = -1000000000;
		for(int x: score)	{
			maxScore = Math.max(maxScore, x);
		}
		Set<String> winner = new HashSet<String>();
		for(int i = 0; i < n; i++)
			if(score[i] == maxScore && name[i] != null)
				winner.add(name[i]);
		name = new String[n];
		score = new int[n];
		Arrays.fill(score, -1000000000);
		for(int qq = 0; qq < n; qq++)		{
			String nameIn = inputStr[qq];
			int scoreIn = inputInt[qq];
			int i = 0;
			for(i = 0; i < n; i++)		{
				if(name[i] == null)
					break;
				if(name[i].equals(nameIn))	{
					score[i] += scoreIn;
					if(score[i] >= maxScore && winner.contains(name[i]))		{
						System.out.println(name[i]);
						return;
					}
				}
			}
			name[i] = nameIn;
			score[i] = scoreIn;
			if(score[i] >= maxScore && winner.contains(name[i]))		{
				System.out.println(name[i]);
				return;
			}
		}
	}
}


import java.io.*;
import java.util.*;
public class A2 {
	public static void main(String[] args) throws IOException	{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] name = new String[1000];
		int[] score = new int[1000];
		int best = -1000000000;
		String win = "";
		int n = Integer.parseInt(br.readLine());
		outer: for(int q = 0; q < n; q++)		{
			StringTokenizer st = new StringTokenizer(br.readLine());
			String curr = st.nextToken();
			int num = Integer.parseInt(st.nextToken());
			int i = 0;
			for(i = 0; i < name.length; i++)			{
				if(name[i] == null)
					break;
				if(name[i].equals(curr))	{
					score[i] += num;
					if(score[i] > best)		{
						best = score[i];
						win = name[i];
					}
					continue outer;
				}
			}
			name[i] = curr;
			score[i] = num;
			if(score[i] > best)		{
				best = score[i];
				win = name[i];
				continue outer;
			}
		}
		System.out.println(win);
	}
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.Map.Entry;

public class Winner {

	/**
	 * @param args
	 */
	public static void main(String[] args) throws IOException {
		// TODO Auto-generated method stub
		BufferedReader r=new BufferedReader(new InputStreamReader(System.in));
		String s=r.readLine();
		int n=Integer.parseInt(s);
		HashMap<String , Integer> hm=new HashMap<String, Integer>();
		String[] names=new String[n];
		int[] scores=new int[n];
		for(int i=0;i<n;i++){
			s=r.readLine();
			String[] sp=s.split(" ");
			names[i]=sp[0];
			scores[i]=Integer.parseInt(sp[1]);
			if(hm.containsKey(sp[0])){
				int score=hm.remove(sp[0]);
				hm.put(sp[0],Integer.parseInt(sp[1])+score);
			}
			else
				hm.put(sp[0], Integer.parseInt(sp[1]));
		}
		LinkedList<String> winners=new LinkedList<String>();
		int max=Integer.MIN_VALUE;
		for(Entry<String,Integer> e:hm.entrySet()){
			max=Math.max(max, e.getValue());
		}
		for(Entry<String,Integer> e:hm.entrySet()){
			if(max==e.getValue()){
				winners.add(e.getKey());
			}
		}

		if(winners.size()==1){
			System.out.println(winners.get(0));
		}
		else {
			hm=new HashMap<String, Integer>();
			for(int i=0;i<n;i++){
				if(hm.containsKey(names[i])){
					int score=hm.remove(names[i]);
					hm.put(names[i],(scores[i])+score);
				}
				else
					hm.put(names[i], (scores[i]));
				if(hm.containsValue(max)){
					System.out.println(names[i]);
				}
			}

		}

	}

	private static int Index(String[] winn, String string) {
		for (int i = 0; i < winn.length; i++) {
			if(winn[i].equals(string))
				return i;
		}
		return -1;
	}

}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.Map.Entry;

public class Winner {

	/**
	 * @param args
	 */
	public static void main(String[] args) throws IOException {
		// TODO Auto-generated method stub
		BufferedReader r=new BufferedReader(new InputStreamReader(System.in));
		String s=r.readLine();
		int n=Integer.parseInt(s);
		HashMap<String , Integer> hm=new HashMap<String, Integer>();
		String[] names=new String[n];
		int[] scores=new int[n];
		for(int i=0;i<n;i++){
			s=r.readLine();
			String[] sp=s.split(" ");
			names[i]=sp[0];
			scores[i]=Integer.parseInt(sp[1]);
			if(hm.containsKey(sp[0])){
				int score=hm.remove(sp[0]);
				hm.put(sp[0],Integer.parseInt(sp[1])+score);
			}
			else
				hm.put(sp[0], Integer.parseInt(sp[1]));
		}
		LinkedList<String> winners=new LinkedList<String>();
		int max=Integer.MIN_VALUE;
		for(Entry<String,Integer> e:hm.entrySet()){
			max=Math.max(max, e.getValue());
		}
		for(Entry<String,Integer> e:hm.entrySet()){
			if(max==e.getValue()){
				winners.add(e.getKey());
			}
		}

		if(winners.size()==1){
			System.out.println(winners.get(0));
		}
		else {
		String[] winn=new String[winners.size()];
		for(int i=0;i<winn.length;i++){
			winn[i]=winners.get(i);
		}
		int[] sco=new int[winners.size()];
		for(int i=0;i<n;i++){
			int index=Index(winn,names[i]);
			if(index!=-1){
				sco[index]+=scores[i];
				if(sco[index]==max){
					System.out.println(names[i]);
					break;
				}
			}

		}
		}

	}

	private static int Index(String[] winn, String string) {
		for (int i = 0; i < winn.length; i++) {
			if(winn[i].equals(string))
				return i;
		}
		return -1;
	}

}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.Map.Entry;

public class Winner {

	/**
	 * @param args
	 */
	public static void main(String[] args) throws IOException {
		// TODO Auto-generated method stub
		BufferedReader r=new BufferedReader(new InputStreamReader(System.in));
		String s=r.readLine();
		int n=Integer.parseInt(s);
		HashMap<String , Integer> hm=new HashMap<String, Integer>();
		String[] names=new String[n];
		int[] scores=new int[n];
		for(int i=0;i<n;i++){
			s=r.readLine();
			String[] sp=s.split(" ");
			names[i]=sp[0];
			scores[i]=Integer.parseInt(sp[1]);
			if(hm.containsKey(sp[0])){
				int score=hm.remove(sp[0]);
				hm.put(sp[0],Integer.parseInt(sp[1])+score);
			}
			else
				hm.put(sp[0], Integer.parseInt(sp[1]));
		}

		int max=-1;
		for(Entry<String,Integer> e:hm.entrySet()){
			max=Math.max(max, e.getValue());
		}

		HashMap<String , Integer> h=new HashMap<String, Integer>();
		HashSet<String> winners=new HashSet<String>();
		for(Entry<String,Integer> e:hm.entrySet()){
		if(e.getValue()==max)winners.add(e.getKey());
		}
		for(int i=0;i<n;i++){
			String name=names[i];
			int sc=scores[i];
			if(h.containsKey(name)){
				int os=h.remove(name);
				if(os+sc==max){
					if(winners.contains(name)){
					System.out.println(name);
					return;
					}
				}
				h.put(name, os+sc);
			}
			else{
				if(sc==max){
					if(winners.contains(name)){
					System.out.println(name);
					return;
					}
				}
				h.put(name, sc);
			}
		}
	}

}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.Map.Entry;

public class Winner {

	/**
	 * @param args
	 */
	public static void main(String[] args) throws IOException {
		// TODO Auto-generated method stub
		BufferedReader r = new BufferedReader(new InputStreamReader(System.in));
		String s = r.readLine();
		int n = Integer.parseInt(s);
		HashMap<String, Integer> hm = new HashMap<String, Integer>();
		String[] names = new String[n];
		int[] scores = new int[n];
		for (int i = 0; i < n; i++) {
			s = r.readLine();
			String[] sp = s.split(" ");
			names[i] = sp[0];
			scores[i] = Integer.parseInt(sp[1]);
			if (hm.containsKey(sp[0])) {
				int score = hm.remove(sp[0]);
				hm.put(sp[0], Integer.parseInt(sp[1]) + score);
			} else
				hm.put(sp[0], Integer.parseInt(sp[1]));
		}

		int max = -1;
		for (Entry<String, Integer> e : hm.entrySet()) {
			max = Math.max(max, e.getValue());
		}

		HashMap<String, Integer> h = new HashMap<String, Integer>();
		HashSet<String> winners = new HashSet<String>();
		for (Entry<String, Integer> e : hm.entrySet()) {
			if (e.getValue() == max)
				winners.add(e.getKey());
		}
		for (int i = 0; i < n; i++) {
			String name = names[i];
			int sc = scores[i];
			if (h.containsKey(name)) {
				int os = h.remove(name);
				if (os + sc >= max) {
					if (winners.contains(name)) {
						System.out.println(name);
						return;
					}
				}
				h.put(name, os + sc);
			} else {
				if (sc >= max) {
					if (winners.contains(name)) {
						System.out.println(name);
						return;
					}
				}
				h.put(name, sc);
			}
		}
	}

}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.Map.Entry;

public class Winner {

	/**
	 * @param args
	 */
	public static void main(String[] args) throws IOException {
		// TODO Auto-generated method stub
		BufferedReader r=new BufferedReader(new InputStreamReader(System.in));
		String s=r.readLine();
		int n=Integer.parseInt(s);
		HashMap<String , Integer> hm=new HashMap<String, Integer>();
		String[] names=new String[n];
		int[] scores=new int[n];
		for(int i=0;i<n;i++){
			s=r.readLine();
			String[] sp=s.split(" ");
			names[i]=sp[0];
			scores[i]=Integer.parseInt(sp[1]);
			if(hm.containsKey(sp[0])){
				int score=hm.remove(sp[0]);
				hm.put(sp[0],Integer.parseInt(sp[1])+score);
			}
			else
				hm.put(sp[0], Integer.parseInt(sp[1]));
		}

		int max=-1;
		for(Entry<String,Integer> e:hm.entrySet()){
			max=Math.max(max, e.getValue());
		}

		HashMap<String , Integer> h=new HashMap<String, Integer>();
		for(int i=0;i<n;i++){
			String name=names[i];
			int sc=scores[i];
			if(h.containsKey(name)){
				int os=h.remove(name);
				if(os+sc==max){
					System.out.println(name);
					return;
				}
				h.put(name, os+sc);
			}
			else{
				if(sc==max){
					System.out.println(name);
					return;
				}
				h.put(name, sc);
			}
		}
	}

}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.Map.Entry;

public class Winner {

	/**
	 * @param args
	 */
	public static void main(String[] args) throws IOException {
		// TODO Auto-generated method stub
		BufferedReader r=new BufferedReader(new InputStreamReader(System.in));
		String s=r.readLine();
		int n=Integer.parseInt(s);
		HashMap<String , Integer> hm=new HashMap<String, Integer>();
		String[] names=new String[n];
		int[] scores=new int[n];
		for(int i=0;i<n;i++){
			s=r.readLine();
			String[] sp=s.split(" ");
			names[i]=sp[0];
			scores[i]=Integer.parseInt(sp[1]);
			if(hm.containsKey(sp[0])){
				int score=hm.remove(sp[0]);
				hm.put(sp[0],Integer.parseInt(sp[1])+score);
			}
			else
				hm.put(sp[0], Integer.parseInt(sp[1]));
		}
		LinkedList<String> winners=new LinkedList<String>();
		int max=Integer.MIN_VALUE;
		for(Entry<String,Integer> e:hm.entrySet()){
			max=Math.max(max, e.getValue());
		}
		for(Entry<String,Integer> e:hm.entrySet()){
			if(max==e.getValue()){
				winners.add(e.getKey());
			}
		}

		if(winners.size()==1){
			System.out.println(winners.get(0));
		}
		else {
			hm=new HashMap<String, Integer>();
			for(int i=0;i<n;i++){
				if(hm.containsKey(names[i])){
					int score=hm.remove(names[i]);
					hm.put(names[i],(scores[i])+score);
				}
				else
					hm.put(names[i], (scores[i]));
				if(hm.containsValue(max)){
					System.out.println(names[i]);
					break;
				}
			}

		}

	}

	private static int Index(String[] winn, String string) {
		for (int i = 0; i < winn.length; i++) {
			if(winn[i].equals(string))
				return i;
		}
		return -1;
	}

}


import java.util.Collection;
import java.util.HashMap;
import java.util.Scanner;
import java.util.Set;

/**
 *
 * @author vasudha
 */
public class Main {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        HashMap<String,Integer> hm = new HashMap();
        String ans = "";
        int max = -1;

        int n,i;
        n = sc.nextInt();
        while(true) {
            if(n==0) break;
            String k;
            int j;
            k = sc.next();
            j = sc.nextInt();

            if(!hm.containsKey(k)) {
                hm.put(k,j);

            } else {
                hm.put(k, hm.get(k)+j);
                if(ans.equals(k)) {
                    max = hm.get(k);
                    Object[] a = hm.values().toArray();
                    Set<String> c = hm.keySet();
                    for(i=0;i<a.length;i++) {
                        if((int)a[i] > max) {
                            max = (int)a[i];
                            ans = (String)c.toArray()[i];
                        }
                    }
                }
            }
            if(hm.get(k) > max) {
                    max = hm.get(k);
                    ans = k;
            }
            n--;
        }

       System.out.println(ans);
    }

}


import java.util.Collection;
import java.util.HashMap;
import java.util.Scanner;
import java.util.Set;

/**
 *
 * @author vasudha
 */
public class Main {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        HashMap<String,Integer> hm = new HashMap();
        HashMap<String, Integer> turn = new HashMap();
        String ans = "";
        int max = -1;

        int n,i=0;
        n = sc.nextInt();
        while(true) {
            if(n==0) break;
            String k;
            int j;
            k = sc.next();
            j = sc.nextInt();

            if(!hm.containsKey(k)) {
                hm.put(k,j);
                turn.put(k, i);
            } else {
                hm.put(k, hm.get(k)+j);
                turn.put(k, i);
                if(ans.equals(k)) {
                    max = hm.get(k);

                }
            }
            if(hm.get(k) > max) {
                    max = hm.get(k);
                    ans = k;
            }
            n--;
            i++;
        }
        int min = 9999;
          Object[] a = hm.values().toArray();
                    Set<String> c = hm.keySet();
                    for(i=0;i<a.length;i++) {
                        if((int)a[i] > max) {
                            max = (int)a[i];
                            if(min < turn.get((String)c.toArray()[i]))  {
                                min = turn.get((String)c.toArray()[i]);
                                ans = (String)c.toArray()[i];
                            }
                        } else if((int)a[i] == max){
                            if(turn.get(ans) > turn.get((String)c.toArray()[i])) {
                                ans = (String)c.toArray()[i];
                                min = turn.get((String)c.toArray()[i]);
                            }
                        }
                    }
       System.out.println(ans);
    }

}


import java.util.Collection;
import java.util.HashMap;
import java.util.Scanner;
import java.util.Set;

/**
 *
 * @author vasudha
 */
public class Main {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        HashMap<String,Integer> hm = new HashMap();
        String ans = "";
        int max = -1;

        int n,i;
        n = sc.nextInt();
        while(true) {
            if(n==0) break;
            String k;
            int j;
            k = sc.next();
            j = sc.nextInt();

            if(!hm.containsKey(k)) {
                hm.put(k,j);
            } else {
                hm.put(k, hm.get(k)+j);
                //System.out.println(hm);
                if(ans.equals(k)) {
                    max = hm.get(k);
                Object[] a = hm.values().toArray();
                Set<String> c = hm.keySet();
                for(i=0;i<a.length;i++) {
                    if((int)a[i] > max) {
                        break;
                    }
                }
                if(i!=a.length) ans = (String)c.toArray()[i];
                }
            }
            if(hm.get(k) > max) {
                    max = hm.get(k);
                    ans = k;
            }

            n--;
        }
       System.out.println(ans);
    }

}


import java.util.ArrayList;
import java.util.HashMap;
import java.util.Queue;
import java.util.Scanner;
import java.util.Stack;

/**
 *
 * @author vasudha
 */
public class Main {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        HashMap<String,Integer> hm = new HashMap();
        String ans ="";
        int max = -1;

        int n;
        n = sc.nextInt();
        while(true) {
            if(n==0) break;
            String k;
            int j;
            k = sc.next();
            j = sc.nextInt();
            if(!hm.containsKey(k)) {
                hm.put(k,j);
            } else {
                hm.put(k, hm.get(k)+j);
            }
            if(hm.get(k) > max) {
                    max = hm.get(k);
                    ans = k;
            }
            n--;
        }

       System.out.println(ans);
    }

}


import java.util.Collection;
import java.util.HashMap;
import java.util.Scanner;
import java.util.Set;

/**
 *
 * @author vasudha
 */
public class Main {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        HashMap<String,Integer> hm = new HashMap();
        String ans = "";
        int max = -1;

        int n,i;
        n = sc.nextInt();
        while(true) {
            if(n==0) break;
            String k;
            int j;
            k = sc.next();
            j = sc.nextInt();

            if(!hm.containsKey(k)) {
                hm.put(k,j);

            } else {
                hm.put(k, hm.get(k)+j);
                if(ans.equals(k)) {
                    max = hm.get(k);

            }
            }
            if(hm.get(k) > max) {
                    max = hm.get(k);
                    ans = k;
            }
            n--;
        }
          Object[] a = hm.values().toArray();
                    Set<String> c = hm.keySet();
                    for(i=0;i<a.length;i++) {
                        if((int)a[i] > max) {
                            max = (int)a[i];
                            ans = (String)c.toArray()[i];
                        }
                    }
       System.out.println(ans);
    }

}


import java.util.Collection;
import java.util.HashMap;
import java.util.Scanner;
import java.util.Set;

/**
 *
 * @author vasudha
 */
public class Main {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        HashMap<String,Integer> hm = new HashMap();
        String ans = "";
        int max = -1;

        int n;
        n = sc.nextInt();
        while(true) {
            if(n==0) break;
            String k;
            int j;
            k = sc.next();
            j = sc.nextInt();

            if(!hm.containsKey(k)) {
                hm.put(k,j);
            } else {
                hm.put(k, hm.get(k)+j);
                if(ans.equals(k)) {
                max = hm.get(k);
                }
            }
            if(hm.get(k) > max) {
                    max = hm.get(k);
                    ans = k;
            }

            n--;
        }
        int i;
        Object[] a = hm.values().toArray();
        Set<String> c = hm.keySet();
        for(i=0;i<a.length;i++) {
            if((int)a[i] > max) {
                break;
            }
        }

        if(i!=a.length) ans = (String)c.toArray()[i];

       System.out.println(ans);
    }

}


import java.util.Collection;
import java.util.HashMap;
import java.util.Scanner;
import java.util.Set;

/**
 *
 * @author vasudha
 */
public class Main {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        HashMap<String,Integer> hm = new HashMap();
        HashMap<String, Integer> t = new HashMap();
        String ans = "";
        int max = -1;
        int[] j = new int[100];
        String[] k= new String[100];
        int n,i=0;
        n = sc.nextInt();
        while(true) {
            if(n==0) break;

            k[i] = sc.next();
            j[i++] = sc.nextInt();

            if(!hm.containsKey(k[i-1])) {
                hm.put(k[i-1],j[i-1]);
            } else {
                hm.put(k[i-1], hm.get(k[i-1])+j[i-1]);
            }

            n--;
        }

        int l = i;

       // System.out.println(hm);

          Object[] a = hm.values().toArray();
                    for(i=0;i<a.length;i++) {
                        if((int)a[i] > max) {
                            max = (int)a[i];
                        }
                    }

                    //System.out.println(max);

                    for(i=0;i<l;i++) {
                            if(!t.containsKey(k[i]))
                           t.put(k[i], j[i]);
                            else
                              t.put(k[i], t.get(k[i])+j[i]);
                            if(t.get(k[i]) >=  max && hm.get(k[i]) == max) {
                                ans = k[i];
                                break;
                            }
                    }

       System.out.println(ans);
    }

}


import java.util.ArrayList;
import java.util.HashMap;
import java.util.Queue;
import java.util.Scanner;
import java.util.Stack;

/**
 *
 * @author vasudha
 */
public class Main {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        HashMap<String,Integer> hm = new HashMap();
        String ans ="";
        int max = 0;

        int n;
        n = sc.nextInt();
        while(true) {
            if(n==0) break;
            String k;
            int j;
            k = sc.next();
            j = sc.nextInt();
            if(!hm.containsKey(k)) {
                hm.put(k,j);
                if(j > max) {
                    max = j;
                    ans = k;
                }
            } else {
                hm.put(k, hm.get(k)+j);
                if(hm.get(k) > max) {
                    max = hm.get(k);
                    ans = k;
                }
            }
            n--;
        }

       //System.out.println(max);
       System.out.println(ans);
    }

}


import java.util.Collection;
import java.util.HashMap;
import java.util.Scanner;
import java.util.Set;

/**
 *
 * @author vasudha
 */
public class Main {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        HashMap<String,Integer> hm = new HashMap();
        HashMap<String, Integer> turn = new HashMap();
        String ans = "";
        int max = -1;

        int n,i=0;
        n = sc.nextInt();
        while(true) {
            if(n==0) break;
            String k;
            int j;
            k = sc.next();
            j = sc.nextInt();

            if(!hm.containsKey(k)) {
                hm.put(k,j);
            } else {
                hm.put(k, hm.get(k)+j);
                if(ans.equals(k)) {
                    max = hm.get(k);                }
            }
            if(hm.get(k) >= max) {
                    max = hm.get(k);
                    ans = k;
                    turn.put(k,i);
            }
            n--;
            i++;
        }
        //System.out.println(turn);
        int min = 9999;
          Object[] a = hm.values().toArray();
                    Set<String> c = hm.keySet();
                    for(i=0;i<a.length;i++) {
                        if((int)a[i] > max) {
                            max = (int)a[i];
                            if(min < turn.get((String)c.toArray()[i]))  {
                                min = turn.get((String)c.toArray()[i]);
                                ans = (String)c.toArray()[i];
                            }
                        } else if((int)a[i] == max){
                            if(!turn.containsKey(ans)) {
                                ans = (String)c.toArray()[i];
                                min = turn.get((String)c.toArray()[i]);
                            } else if(!turn.containsKey((String)c.toArray()[i])) {
                                continue;
                            } else if(turn.get(ans) > turn.get((String)c.toArray()[i])) {
                                ans = (String)c.toArray()[i];
                                min = turn.get((String)c.toArray()[i]);
                            }
                        }
                    }
       System.out.println(ans);
    }

}


import java.util.Collection;
import java.util.HashMap;
import java.util.Scanner;
import java.util.Set;

/**
 *
 * @author vasudha
 */
public class Main {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        HashMap<String,Integer> hm = new HashMap();
        HashMap<String, Integer> turn = new HashMap();
        String ans = "";
        int max = -1;

        int n,i=0;
        n = sc.nextInt();
        while(true) {
            if(n==0) break;
            String k;
            int j;
            k = sc.next();
            j = sc.nextInt();

            if(!hm.containsKey(k)) {
                hm.put(k,j);
                turn.put(k, i);
            } else {
                hm.put(k, hm.get(k)+j);
                turn.put(k, i);
                if(ans.equals(k)) {
                    max = hm.get(k);

                }
            }
            if(hm.get(k) > max) {
                    max = hm.get(k);
                    ans = k;
            }
            n--;
            i++;
        }
        int min = 9999;
          Object[] a = hm.values().toArray();
                    Set<String> c = hm.keySet();
                    for(i=0;i<a.length;i++) {
                        if((int)a[i] > max) {
                            max = (int)a[i];
                            if(min < turn.get((String)c.toArray()[i]))  {
                                min = turn.get((String)c.toArray()[i]);
                                ans = (String)c.toArray()[i];
                            }
                        }
                    }
       System.out.println(ans);
    }

}


import java.util.Collection;
import java.util.HashMap;
import java.util.Scanner;
import java.util.Set;

/**
 *
 * @author vasudha
 */
public class Main {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        HashMap<String,Integer> hm = new HashMap();
        HashMap<String, Integer> turn = new HashMap();
        String ans = "";
        int max = -1;

        int n,i=0;
        n = sc.nextInt();
        while(true) {
            if(n==0) break;
            String k;
            int j;
            k = sc.next();
            j = sc.nextInt();

            if(!hm.containsKey(k)) {
                hm.put(k,j);
            } else {
                hm.put(k, hm.get(k)+j);
                if(ans.equals(k)) {
                    max = hm.get(k);                }
            }
            if(hm.get(k) >= max) {
                    max = hm.get(k);
                    ans = k;
                    turn.put(k,i);
            }
            n--;
            i++;
        }
        //System.out.println(turn);

          Object[] a = hm.values().toArray();
                    Set<String> c = hm.keySet();
                    for(i=0;i<a.length;i++) {
                        if((int)a[i] > max) {
                            max = (int)a[i];
                            ans = (String)c.toArray()[i];
                        } else if((int)a[i] == max){
                            if(!turn.containsKey(ans)) {
                                ans = (String)c.toArray()[i];
                            } else if(!turn.containsKey((String)c.toArray()[i])) {
                                continue;
                            } else if(turn.get(ans) > turn.get((String)c.toArray()[i])) {
                                ans = (String)c.toArray()[i];
                            }
                        }
                    }
       System.out.println(ans);
    }

}


/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package javaapplication12;

import java.util.Collection;
import java.util.HashMap;
import java.util.Scanner;
import java.util.Set;

/**
 *
 * @author vasudha
 */
public class JavaApplication12 {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        HashMap<String,Integer> hm = new HashMap();
        String ans = "";
        int max = -1;

        int n,i;
        n = sc.nextInt();
        while(true) {
            if(n==0) break;
            String k;
            int j;
            k = sc.next();
            j = sc.nextInt();

            if(!hm.containsKey(k)) {
                hm.put(k,j);

            } else {
                hm.put(k, hm.get(k)+j);
                if(ans.equals(k)) {
                    max = hm.get(k);

            }
            }
            if(hm.get(k) > max) {
                    max = hm.get(k);
                    ans = k;
            }
            n--;
        }
          Object[] a = hm.values().toArray();
                    Set<String> c = hm.keySet();
                    for(i=0;i<a.length;i++) {
                        if((int)a[i] > max) {
                            max = (int)a[i];
                            ans = (String)c.toArray()[i];
                        }
                    }
       System.out.println(ans);
    }

}


import java.util.Collection;
import java.util.HashMap;
import java.util.Scanner;
import java.util.Set;

/**
 *
 * @author vasudha
 */
public class Main {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        HashMap<String,Integer> hm = new HashMap();
        HashMap<String, Integer> turn = new HashMap();
        String ans = "";
        int max = -1;

        int n,i=0;
        n = sc.nextInt();
        while(true) {
            if(n==0) break;
            String k;
            int j;
            k = sc.next();
            j = sc.nextInt();

            if(!hm.containsKey(k)) {
                hm.put(k,j);
                turn.put(k, i);
            } else {
                hm.put(k, hm.get(k)+j);
                if(ans.equals(k)) {
                    max = hm.get(k);                }
            }
            if(hm.get(k) > max) {
                    max = hm.get(k);
                    ans = k;
                    turn.put(k,i);
            }
            n--;
            i++;
        }
       // System.out.println(turn);
        int min = 0;
          Object[] a = hm.values().toArray();
                    Set<String> c = hm.keySet();
                    for(i=0;i<a.length;i++) {
                        if((int)a[i] > max) {
                            max = (int)a[i];
                            if(min > turn.get((String)c.toArray()[i]))  {
                                min = turn.get((String)c.toArray()[i]);
                                ans = (String)c.toArray()[i];
                            }
                        } else if((int)a[i] == max){
                            if(turn.get(ans) < turn.get((String)c.toArray()[i])) {
                                ans = (String)c.toArray()[i];
                                min = turn.get((String)c.toArray()[i]);
                            }
                        }
                    }
       System.out.println(ans);
    }

}


import java.util.Collection;
import java.util.HashMap;
import java.util.Scanner;
import java.util.Set;

/**
 *
 * @author vasudha
 */
public class Main {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        HashMap<String,Integer> hm = new HashMap();
        String ans = "";
        int max = -1;

        int n,i;
        n = sc.nextInt();
        while(true) {
            if(n==0) break;
            String k;
            int j;
            k = sc.next();
            j = sc.nextInt();

            if(!hm.containsKey(k)) {
                hm.put(k,j);
                if(hm.get(k) > max) {
                    max = hm.get(k);
                    ans = k;
                }
            } else {
                hm.put(k, hm.get(k)+j);
                if(ans.equals(k)) {
                    max = -1;
                    //System.out.println(hm);
                    Object[] a = hm.values().toArray();
                    Set<String> c = hm.keySet();
                    for(i=0;i<a.length;i++) {
                        if((int)a[i] > max) {
                            max = (int)a[i];
                            ans = (String)c.toArray()[i];
                        }
                    }
                }
            }
            n--;
        }

        Object[] a = hm.values().toArray();
                    Set<String> c = hm.keySet();
                    for(i=0;i<a.length;i++) {
                        if((int)a[i] > max) {
                            break;

                        }
                    }

                    if(i!=a.length)  ans = (String)c.toArray()[i];

       System.out.println(ans);
    }

}


import java.util.ArrayList;
import java.util.HashMap;
import java.util.Queue;
import java.util.Scanner;
import java.util.Stack;

public class Main {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        HashMap<String,Integer> hm = new HashMap();
        String ans ="";
        int max = -1;

        int n;
        n = sc.nextInt();
        while(true) {
            if(n==0) break;
            String k;
            int j;
            k = sc.next();
            j = sc.nextInt();
            if(j>=0) {
            if(!hm.containsKey(k)) {
                hm.put(k,j);
            } else {
                hm.put(k, hm.get(k)+j);
            }
            if(hm.get(k) > max) {
                    max = hm.get(k);
                    ans = k;
            }
            }
            n--;
        }

       System.out.println(ans);
    }

}


import java.util.HashMap;
import java.util.Scanner;

/**
 *
 * @author vasudha
 */
public class Main {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        HashMap<String,Integer> hm = new HashMap();
        String ans = "";
        int max = -1;

        int n;
        n = sc.nextInt();
        while(true) {
            if(n==0) break;
            String k;
            int j;
            k = sc.next();
            j = sc.nextInt();

            if(!hm.containsKey(k)) {
                hm.put(k,j);
            } else {
                hm.put(k, hm.get(k)+j);
            }
            if(ans.equals(k)) {
                max = hm.get(k);
            }
            if(hm.get(k) > max) {
                    max = hm.get(k);
                    ans = k;
            }

            n--;
        }

       System.out.println(ans);
    }

}


import java.util.Collection;
import java.util.HashMap;
import java.util.Scanner;
import java.util.Set;

/**
 *
 * @author vasudha
 */
public class Main {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        HashMap<String,Integer> hm = new HashMap();
        String ans = "";
        int max = -1;

        int n,i;
        n = sc.nextInt();
        while(true) {
            if(n==0) break;
            String k;
            int j;
            k = sc.next();
            j = sc.nextInt();

            if(!hm.containsKey(k)) {
                hm.put(k,j);

            } else {
                hm.put(k, hm.get(k)+j);
                if(ans.equals(k)) {
                    max = -1;
                    Object[] a = hm.values().toArray();
                    Set<String> c = hm.keySet();
                    for(i=0;i<a.length;i++) {
                        if((int)a[i] > max) {
                            max = (int)a[i];
                            ans = (String)c.toArray()[i];
                        }
                    }
                }
            }
            if(hm.get(k) > max) {
                    max = hm.get(k);
                    ans = k;
            }
            n--;
        }

       System.out.println(ans);
    }

}


import java.util.Collection;
import java.util.HashMap;
import java.util.Scanner;
import java.util.Set;

/**
 *
 * @author vasudha
 */
public class Main {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        HashMap<String,Integer> hm = new HashMap();
        HashMap<String, Integer> t = new HashMap();
        String ans = "";
        int max = -1;
        int[] j = new int[1000];
        String[] k= new String[1000];
        int n,i=0;
        n = sc.nextInt();
        while(true) {
            if(n==0) break;

            k[i] = sc.next();
            j[i++] = sc.nextInt();

            if(!hm.containsKey(k[i-1])) {
                hm.put(k[i-1],j[i-1]);
            } else {
                hm.put(k[i-1], hm.get(k[i-1])+j[i-1]);
            }

            n--;
        }

        int l = i;

       // System.out.println(hm);

          Object[] a = hm.values().toArray();
                    for(i=0;i<a.length;i++) {
                        if((int)a[i] > max) {
                            max = (int)a[i];
                        }
                    }

                    //System.out.println(max);

                    for(i=0;i<l;i++) {
                            if(!t.containsKey(k[i]))
                           t.put(k[i], j[i]);
                            else
                              t.put(k[i], t.get(k[i])+j[i]);
                            if(t.get(k[i]) >=  max && hm.get(k[i]) == max) {
                                ans = k[i];
                                break;
                            }
                    }

       System.out.println(ans);
    }

}


import java.util.Collection;
import java.util.HashMap;
import java.util.Scanner;
import java.util.Set;

/**
 *
 * @author vasudha
 */
public class Main {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        HashMap<String,Integer> hm = new HashMap();
        HashMap<String, Integer> turn = new HashMap();
        String ans = "";
        int max = -1;

        int n,i=0;
        n = sc.nextInt();
        while(true) {
            if(n==0) break;
            String k;
            int j;
            k = sc.next();
            j = sc.nextInt();

            if(!hm.containsKey(k)) {
                hm.put(k,j);
                turn.put(k, i);
            } else {
                hm.put(k, hm.get(k)+j);
                if(ans.equals(k)) {
                    max = hm.get(k);

                }
            }
            if(hm.get(k) > max) {
                    max = hm.get(k);
                    ans = k;
            }
            n--;
            i++;
        }
        int min = 9999;
          Object[] a = hm.values().toArray();
                    Set<String> c = hm.keySet();
                    for(i=0;i<a.length;i++) {
                        if((int)a[i] > max) {
                            max = (int)a[i];
                            if(min < turn.get((String)c.toArray()[i]))  {
                                min = turn.get((String)c.toArray()[i]);
                                ans = (String)c.toArray()[i];
                            }
                        } else if((int)a[i] == max){
                            if(turn.get(ans) > turn.get((String)c.toArray()[i])) {
                                ans = (String)c.toArray()[i];
                                min = turn.get((String)c.toArray()[i]);
                            }
                        }
                    }
       System.out.println(ans);
    }

}


import java.util.Collection;
import java.util.HashMap;
import java.util.Scanner;
import java.util.Set;

/**
 *
 * @author vasudha
 */
public class Main {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        HashMap<String,Integer> hm = new HashMap();
        HashMap<String, Integer> turn = new HashMap();
        String ans = "";
        int max = -1;

        int n,i=0;
        n = sc.nextInt();
        while(true) {
            if(n==0) break;
            String k;
            int j;
            k = sc.next();
            j = sc.nextInt();

            if(!hm.containsKey(k)) {
                hm.put(k,j);
                turn.put(k, i);
            } else {
                hm.put(k, hm.get(k)+j);
                turn.put(k, i);
                if(ans.equals(k)) {
                    max = hm.get(k);

                }
            }
            if(hm.get(k) > max) {
                    max = hm.get(k);
                    ans = k;
            }
            n--;
            i++;
        }
        int min = turn.get(ans);
          Object[] a = hm.values().toArray();
                    Set<String> c = hm.keySet();
                    for(i=0;i<a.length;i++) {
                        if((int)a[i] >= max) {
                            max = (int)a[i];
                            if(min < turn.get((String)c.toArray()[i]))  {
                                min = turn.get((String)c.toArray()[i]);
                                ans = (String)c.toArray()[i];
                            }
                        }
                    }
       System.out.println(ans);
    }

}


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

public class A {
  public static void main (String[] args) {
    Map<String, Integer> score = new HashMap<String, Integer>(),
      time = new HashMap<String, Integer>();
    int n = xint();
    while (n-- > 0) {
      String[] i = xline().split(" ");
      String p = i[0];
      int s = Integer.parseInt(i[1]);
      if (score.containsKey(p)) {
        score.put(p, score.get(p) + s);
      } else {
        score.put(p, s);
      }
      if (s > 0) time.put(p, n);
    }
    int maxScore = 0;
    int t = 0;
    String winner = "";
    for (Map.Entry<String, Integer> e : score.entrySet()) {
      if (maxScore < e.getValue() ||
          (maxScore == e.getValue() && time.get(e.getKey()) > t)) {
        maxScore = e.getValue();
        winner = e.getKey();
        t = time.get(e.getKey());
      }
    }
    System.out.println(winner);
  }

  private static Scanner sc = new Scanner(new InputStreamReader(System.in));
  static final int xint() {
    return sc.nextInt();
  }
  static final int[] xints(int n) {
    int[] a = new int[n];
    for (int i = 0; i < n; i++) a[i] = sc.nextInt();
    return a;
  }
  static final int[] xints(int[] a, int from, int to) {
    // from: inclusive, to: exclusive
    for (int i = from; i < to; i++) a[i] = sc.nextInt();
    return a;
  }
  static final long xlong() {
    return sc.nextLong();
  }
  static final long[] xlongs(int n) {
    long[] a = new long[n];
    for (int i = 0; i < n; i++) a[i] = sc.nextLong();
    return a;
  }
  static final String xline() {
    String s = sc.nextLine();
    if (s.equals("")) s = sc.nextLine();
    return s;
  }
  static final String[] xlines(int n) {
    String[] a = new String[n];
    for (int i = 0; i < n; i++) a[i] = xline();
    return a;
  }
  static final boolean hasx() {
    return sc.hasNext();
  }
  static final void dprint(Object... args) {
    if (System.getProperty("ONLINE_JUDGE") != null &&
        System.getProperty("ONLINE_JUDGE").equals("true")) return;
    for (Object o : args) System.out.print(o + " ");
  }
  static final void dprintln(Object... args) {
    if (System.getProperty("ONLINE_JUDGE") != null &&
        System.getProperty("ONLINE_JUDGE").equals("true")) return;
    for (Object o : args) System.out.print(o + " ");
    System.out.println();
  }
}


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

public class A {
  public static void main (String[] args) {
    Map<String, Integer> score = new HashMap<String, Integer>(),
      time = new HashMap<String, Integer>();
    int n = xint();
    while (n-- > 0) {
      String[] i = xline().split(" ");
      String p = i[0];
      int s = Integer.parseInt(i[1]);
      if (score.containsKey(p)) {
        score.put(p, score.get(p) + s);
      } else {
        score.put(p, s);
      }
      time.put(p, n);
    }
    int maxScore = 0;
    int t = 0;
    String winner = "";
    for (Map.Entry<String, Integer> e : score.entrySet()) {
      if (maxScore < e.getValue() ||
          (maxScore == e.getValue() && time.get(e.getKey()) > t)) {
        maxScore = e.getValue();
        winner = e.getKey();
      }
    }
    System.out.println(winner);
  }

  private static Scanner sc = new Scanner(new InputStreamReader(System.in));
  static final int xint() {
    return sc.nextInt();
  }
  static final int[] xints(int n) {
    int[] a = new int[n];
    for (int i = 0; i < n; i++) a[i] = sc.nextInt();
    return a;
  }
  static final int[] xints(int[] a, int from, int to) {
    // from: inclusive, to: exclusive
    for (int i = from; i < to; i++) a[i] = sc.nextInt();
    return a;
  }
  static final long xlong() {
    return sc.nextLong();
  }
  static final long[] xlongs(int n) {
    long[] a = new long[n];
    for (int i = 0; i < n; i++) a[i] = sc.nextLong();
    return a;
  }
  static final String xline() {
    String s = sc.nextLine();
    if (s.equals("")) s = sc.nextLine();
    return s;
  }
  static final String[] xlines(int n) {
    String[] a = new String[n];
    for (int i = 0; i < n; i++) a[i] = xline();
    return a;
  }
  static final boolean hasx() {
    return sc.hasNext();
  }
  static final void dprint(Object... args) {
    if (System.getProperty("ONLINE_JUDGE") != null &&
        System.getProperty("ONLINE_JUDGE").equals("true")) return;
    for (Object o : args) System.out.print(o + " ");
  }
  static final void dprintln(Object... args) {
    if (System.getProperty("ONLINE_JUDGE") != null &&
        System.getProperty("ONLINE_JUDGE").equals("true")) return;
    for (Object o : args) System.out.print(o + " ");
    System.out.println();
  }
}


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

public class A {
  public static void main (String[] args) {
    Map<String, Integer> m = new HashMap<String, Integer>();
    int n = xint();
    int maxScore = 0;
    String winner = "";
    while (n-- > 0) {
      String[] i = xline().split(" ");
      String p = i[0];
      int s = Integer.parseInt(i[1]);
      if (m.containsKey(p)) {
        m.put(p, m.get(p) + s);
      } else {
        m.put(p, s);
      }
      if (maxScore < m.get(p)) {
        maxScore = m.get(p);
        winner = p;
      }
    }
    System.out.println(winner);
  }

  private static Scanner sc = new Scanner(new InputStreamReader(System.in));
  static final int xint() {
    return sc.nextInt();
  }
  static final int[] xints(int n) {
    int[] a = new int[n];
    for (int i = 0; i < n; i++) a[i] = sc.nextInt();
    return a;
  }
  static final int[] xints(int[] a, int from, int to) {
    // from: inclusive, to: exclusive
    for (int i = from; i < to; i++) a[i] = sc.nextInt();
    return a;
  }
  static final long xlong() {
    return sc.nextLong();
  }
  static final long[] xlongs(int n) {
    long[] a = new long[n];
    for (int i = 0; i < n; i++) a[i] = sc.nextLong();
    return a;
  }
  static final String xline() {
    String s = sc.nextLine();
    if (s.equals("")) s = sc.nextLine();
    return s;
  }
  static final String[] xlines(int n) {
    String[] a = new String[n];
    for (int i = 0; i < n; i++) a[i] = xline();
    return a;
  }
  static final boolean hasx() {
    return sc.hasNext();
  }
  static final void dprint(Object... args) {
    if (System.getProperty("ONLINE_JUDGE") != null &&
        System.getProperty("ONLINE_JUDGE").equals("true")) return;
    for (Object o : args) System.out.print(o + " ");
  }
  static final void dprintln(Object... args) {
    if (System.getProperty("ONLINE_JUDGE") != null &&
        System.getProperty("ONLINE_JUDGE").equals("true")) return;
    for (Object o : args) System.out.print(o + " ");
    System.out.println();
  }
}


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

public class A {
  public static void main (String[] args) {
    Map<String, Integer> score = new HashMap<String, Integer>(),
      time = new HashMap<String, Integer>();
    int n = xint();
    while (n-- > 0) {
      String[] i = xline().split(" ");
      String p = i[0];
      int s = Integer.parseInt(i[1]);
      if (score.containsKey(p)) {
        score.put(p, score.get(p) + s);
      } else {
        score.put(p, s);
      }
      if (s > 0) time.put(p, n);
    }
    int maxScore = 0;
    int t = 0;
    String winner = "";
    for (Map.Entry<String, Integer> e : score.entrySet()) {
      if (maxScore < e.getValue() ||
          (maxScore == e.getValue() && time.get(e.getKey()) > t)) {
        maxScore = e.getValue();
        winner = e.getKey();
      }
    }
    System.out.println(winner);
  }

  private static Scanner sc = new Scanner(new InputStreamReader(System.in));
  static final int xint() {
    return sc.nextInt();
  }
  static final int[] xints(int n) {
    int[] a = new int[n];
    for (int i = 0; i < n; i++) a[i] = sc.nextInt();
    return a;
  }
  static final int[] xints(int[] a, int from, int to) {
    // from: inclusive, to: exclusive
    for (int i = from; i < to; i++) a[i] = sc.nextInt();
    return a;
  }
  static final long xlong() {
    return sc.nextLong();
  }
  static final long[] xlongs(int n) {
    long[] a = new long[n];
    for (int i = 0; i < n; i++) a[i] = sc.nextLong();
    return a;
  }
  static final String xline() {
    String s = sc.nextLine();
    if (s.equals("")) s = sc.nextLine();
    return s;
  }
  static final String[] xlines(int n) {
    String[] a = new String[n];
    for (int i = 0; i < n; i++) a[i] = xline();
    return a;
  }
  static final boolean hasx() {
    return sc.hasNext();
  }
  static final void dprint(Object... args) {
    if (System.getProperty("ONLINE_JUDGE") != null &&
        System.getProperty("ONLINE_JUDGE").equals("true")) return;
    for (Object o : args) System.out.print(o + " ");
  }
  static final void dprintln(Object... args) {
    if (System.getProperty("ONLINE_JUDGE") != null &&
        System.getProperty("ONLINE_JUDGE").equals("true")) return;
    for (Object o : args) System.out.print(o + " ");
    System.out.println();
  }
}


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

public class A {
  public static void main (String[] args) {
    int n = xint();
    String[] ps = new String[n];
    int[] ss = new int[n];
    for (int i = 0; i < n; i++) {
      String[] in = xline().split(" ");
      ps[i] = in[0];
      ss[i] = Integer.parseInt(in[1]);
    }

    Map<String, Integer> score = new HashMap<String, Integer>();
    int maxScore = 0;
    for (int i = 0; i < n; i++) {
      if (score.containsKey(ps[i])) {
        score.put(ps[i], score.get(ps[i]) + ss[i]);
      } else {
        score.put(ps[i], ss[i]);
      }
      maxScore = Math.max(maxScore, score.get(ps[i]));
    }
    score.clear();
    for (int i = 0; i < n; i++) {
      if (score.containsKey(ps[i])) {
        score.put(ps[i], score.get(ps[i]) + ss[i]);
      } else {
        score.put(ps[i], ss[i]);
      }
      if (maxScore <= score.get(ps[i])) {
        System.out.println(ps[i]);
        return;
      }
    }
  }

  private static Scanner sc = new Scanner(new InputStreamReader(System.in));
  static final int xint() {
    return sc.nextInt();
  }
  static final int[] xints(int n) {
    int[] a = new int[n];
    for (int i = 0; i < n; i++) a[i] = sc.nextInt();
    return a;
  }
  static final int[] xints(int[] a, int from, int to) {
    // from: inclusive, to: exclusive
    for (int i = from; i < to; i++) a[i] = sc.nextInt();
    return a;
  }
  static final long xlong() {
    return sc.nextLong();
  }
  static final long[] xlongs(int n) {
    long[] a = new long[n];
    for (int i = 0; i < n; i++) a[i] = sc.nextLong();
    return a;
  }
  static final String xline() {
    String s = sc.nextLine();
    if (s.equals("")) s = sc.nextLine();
    return s;
  }
  static final String[] xlines(int n) {
    String[] a = new String[n];
    for (int i = 0; i < n; i++) a[i] = xline();
    return a;
  }
  static final boolean hasx() {
    return sc.hasNext();
  }
  static final void dprint(Object... args) {
    if (System.getProperty("ONLINE_JUDGE") != null &&
        System.getProperty("ONLINE_JUDGE").equals("true")) return;
    for (Object o : args) System.out.print(o + " ");
  }
  static final void dprintln(Object... args) {
    if (System.getProperty("ONLINE_JUDGE") != null &&
        System.getProperty("ONLINE_JUDGE").equals("true")) return;
    for (Object o : args) System.out.print(o + " ");
    System.out.println();
  }
}


#include <stdio.h>

int sign[6],k;
char card[15];

void win(int clo,int m)
{
    int i,j;

    for(i=0; i<clo; i++)
    {
        for(j=i; j<12; j=j+clo)
            if(card[j]=='O')
                break;

        if(j>=12)
        {
            k++;

            sign[m]=clo;

            break;
        }
    }

    return;
}

int main()
{
    int n,i,j;

    scanf("%d",&n);

    while(n)
    {
        k=0;

        for(i=0; i<6; i++)
            sign[i]=0;

        scanf("%s",card);

        win(12,0);
        win(6,1);
        win(4,2);
        win(3,3);
        win(2,4);
        win(1,5);

        if(k==0)
            printf("0\n");
        else
        {
            printf("%d ",k);

            for(i=0; i<6 && (k!=1); i++)
                if(sign[i])
                {
                    k--;
                    printf("%dx%d ",12/sign[i],sign[i]);
                }

            for(; i<6; i++)
                if(sign[i])
                {
                    printf("%dx%d\n",12/sign[i],sign[i]);
                }
        }

        n--;
    }
    return 0;
}


#include <stdio.h>

char row[13];
int debug = 0;

int check_rows(int b, char cards[][b]);
int move(int a, int b);

int main()
{
	int t;
	scanf("%d", &t);
	int i, j;

	for(i = 0;i < t;i++)
	{
		scanf(" %[^\n]s", row);

		int total = move(1,12) + move(2,6) + move(3,4) + move(4,3) + move(6,2) + move(12,1);

		printf("%d", total);

		if(move(1,12))
		{
			printf(" 1x12");
		}
		if(move(2,6))
		{
			printf(" 2x6");
		}
		if(move(3,4))
		{
			printf(" 3x4");
		}
		if(move(4,3))
		{
			printf(" 4x3");
		}
		if (move(6,2))
		{
			printf(" 6x2");
		}
		if(move(12,1))
		{
			printf(" 12x1");
		}

		printf("\n");
	}

	return 0;
}

int move(int a, int b)
{
	char cards[a][b];
	int i, j;

	for(i = 0;i < a;i++)
	{
		for(j = 0;j < b;j++)
		{
			cards[i][j] = *(row + i*b + j);
		}
	}

	if(debug)
		{
		for(i = 0;i < a;i++)
		{
			for(j = 0;j < b;j++)
			{
				printf("%c ", cards[i][j]);
			}
			printf("\n");
		}
		printf("\n");
	}

	return check_rows(b, cards);
}

int check_rows(int b, char cards[][b])
{
	int a = 12/b;
	int i, j;
	int win;

	for(i = 0;i < b;i++)
	{
		win = 1;
		for(j = 0;j < a;j++)
		{
			if(cards[j][i] == 'O')
			{
				win = 0;
			}
		}

		if(win)
		{
			return 1;
		}
	}

	return 0;
}
/* 1513465271505 */


#include <stdio.h>
#include <string.h>

int teste(char string[], int a, int b)
{
	for (int j = 0; j < b; ++j)
		{
			int test = 0;
			for (int l = 0; l < a; ++l)
			{
				if (string[j + l*b] == 'X') test++;
				if(test == a )
				{
					return 1;
				}
			}
		}
	return 0;
}

int main(int argc, char const *argv[])
{
	int n, k, counter, res[6] = {0, 0, 0, 0, 0, 0};
	char string[12];
	scanf("%d", &n);
	for (int i = 0; i < n; ++i)
	{
		scanf(" %[^\n]", string);
		res[0] = teste(string, 1, 12);
		counter += res[0];
		res[1] = teste(string, 2, 6);
		counter += res[1];
		res[2] = teste(string, 3, 4);
		counter += res[2];
		res[3] = teste(string, 4, 3);
		counter += res[3];
		res[4] = teste(string, 6, 2);
		counter += res[4];
		res[5] = teste(string, 12, 1);
		counter += res[5];
		printf("%d", counter);
		if (res[0]) printf(" 1x12");
		if (res[1]) printf(" 2x6");
		if (res[2]) printf(" 3x4");
		if (res[3]) printf(" 4x3");
		if (res[4]) printf(" 6x2");
		if (res[5]) printf(" 12x1");
		counter = 0;
		for (int j = 0; j < 6; ++j) res[j] = 0;
		printf("\n");

	}
	return 0;
}


#include <stdio.h>
#include <string.h>

int is3equal(char var1,char var2, char var3);
int is4equal(char var1, char var2, char var3, char var4);
int is5equal(char var1, char var2, char var3, char var4, char var5);
int is7equal(char var1, char var2, char var3, char var4, char var5, char var6, char var7);

int main()
{
	int tt,i;
	int sum,flag_1_12,flag_2_6,flag_3_4,flag_4_3, flag_6_2,flag_12_1,lastflag,ar[6];
	char str[12];
	scanf("%d",&tt);
	while(tt--)
	{
		scanf("%s",str);
		flag_1_12=flag_2_6=flag_3_4=flag_4_3=flag_6_2=flag_12_1=0;

		// For the 1x12 matrix
		for(i=0;i<12;i++)
		{
			if(str[i]=='X')
			{
				flag_1_12=1;
				break;
			}
		}

		// For the 2x6 matrix
		if( is3equal(str[0],str[6],'X') || is3equal(str[1],str[7],'X') || is3equal(str[2],str[8],'X') || is3equal(str[3],str[9],'X') || is3equal(str[4],str[10],'X') || is3equal(str[5],str[11],'X'))
		{
			flag_2_6=1;
		}

		// For the 3x4 matrix
		if( is4equal(str[0],str[4],str[8],'X') || is4equal(str[1],str[5],str[9],'X') || is4equal(str[2],str[6],str[10],'X') || is4equal(str[3],str[7],str[11],'X'))
		{
			flag_3_4=1;
		}

		//For the 4x3 matrix
		if( is5equal(str[0],str[3],str[6],str[9],'X') || is5equal(str[1],str[4],str[7],str[10],'X') || is5equal(str[2],str[5],str[8],str[11],'X') )
		{
			flag_4_3=1;
		}

		// For the 6x2 matrix
		if(is7equal(str[0],str[2],str[4],str[6],str[8],str[10],'X') || is7equal(str[1],str[3],str[5],str[7],str[9],str[11],'X'))
		{
			flag_6_2=1;
		}

		// For the 12x1 matrix
		lastflag=0;
		for(i=0;i<12;i++)
		{
			if(str[i]!='X')
			{
				lastflag=1;
				break;
			}
		}
		if(lastflag==0)
			flag_12_1=1;

		printf("%d ",flag_1_12+flag_2_6+flag_3_4+flag_4_3+flag_6_2+flag_12_1 );
		if(flag_1_12==1)
			printf("1x12 ");
		if(flag_2_6==1)
			printf("2x6 ");
		if(flag_3_4==1)
			printf("3x4 ");
		if(flag_4_3==1)
			printf("4x3 ");
		if(flag_6_2==1)
			printf("6x2 ");
		if(flag_12_1==1)
			printf("12x1 ");
		printf("\n");
	}
	return 0;
}

int is3equal(char var1,char var2, char var3)
{
	if(var1==var2 && var2==var3)
		return 1;
	else
		return 0;
}

int is4equal(char var1, char var2, char var3, char var4)
{
	if(var1==var2 && var2==var3 && var3==var4)
		return 1;
	else
		return 0;
}

int is5equal(char var1, char var2, char var3, char var4, char var5)
{
	if(var1==var2 && var2==var3 && var3==var4 && var4==var5)
		return 1;
	else
		return 0;
}

int is7equal(char var1, char var2, char var3, char var4, char var5, char var6, char var7)
{
	if(var1==var2 && var2==var3 && var3==var4 && var4==var5 && var5==var6 && var6==var7)
		return 1;
	else
		return 0;
}


///package CodeForce;
import java.io.*;
import java.util.*;
/**
 *
 * @author prabhat
 */
public class P400A {

	   static final int MAX1 = 1000000+10;
	   static final long mod = 1000000007;
	   static final long MOD = 100000000000000007L;
	   static int phiSum[] = new int[MAX1];
	   static int phi[] = new int[MAX1];
	   static long[] res=new long[MAX1];
	   static int a[];
	   static long BIT[];
	   static int n,m,k,p;
	   static boolean[] b;
	   static long[][] pascal;
           static long[][] dp;
           static LinkedList<Integer> list[];
           static ArrayList<Integer> l;
           static TreeSet<Integer> ts;
           static int max=1<<11;
           static char[] s;
	    public static void main(String[] args) throws IOException{

	        InputReader in = new InputReader(System.in);
               //BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
	        PrintWriter pw = new PrintWriter(System.out,true);
              int t=in.ii();
              while(t-->0)
              {
                s=in.next().trim().toCharArray();
               ts=new TreeSet<>();
                for(int i=1;i<=12;i++)
                {
                   if(12%i==0)
                   {
                      if(sol(i,12/i))
                          ts.add(i);
                   }
                }
                pw.print(ts.size()+" ");
                for(int o:ts)
                    pw.print(o+"x"+(12/o)+" ");
                pw.println();
              }

	      pw.close();
	    }
         static boolean sol(int a,int b)
            {
               boolean res=false;
               for(int c=0;c<b;c++)
               {
                  boolean f=true;
                  for(int r=0;r<a;r++)
                  {
                    f&=(s[r*b+c]=='X');
                  }
                  res|=f;
               }
            return res;
            }
            static void pascal()
	    {
	  	  pascal=new long[max][max];
	  	  for(int i=0;i<max;i++)
	  	  {
	  		  pascal[i][0]=1L;
	  		  for(int j=1;j<=i;j++)
	  		  {
	  			  pascal[i][j]=(int) ((pascal[i-1][j]+pascal[i-1][j-1])%mod);
	  		  }
	  	  }

	    }
       public static long pow(long n,long p)
	{
		long  result = 1L;
		  if(p==0)
		    return 1L;
		if (p==1)
		    return n;
		while(p!=0)
		{
		    if(p%2==1)
		        result *= n;
		    p >>=1;
		    n*=n;
		}
		return result;

	}

    boolean nextPermutation(int[] p) {
        for (int a = p.length - 2; a >= 0; --a)
        {
            if (p[a] < p[a + 1])
                for (int b = p.length - 1; ; --b)
                    if (p[b] > p[a]) {
                        int t = p[a];
                        p[a] = p[b];
                        p[b] = t;
                        for (++a, b = p.length - 1; a < b; ++a, --b)
                        {
                            t = p[a];
                            p[a] = p[b];
                            p[b] = t;
                        }
                        return true;
                    }
        }
        return false;
     }

	    public static long nCr(long total, long choose)
		{
			if(total < choose)
				return 0;
			if(choose == 0 || choose == total)
				return 1;
			return nCr(total-1,choose-1)+nCr(total-1,choose);
		}
	    static void compute() {
	    		for (int i = 0; i < MAX1; i++) {
	    			phi[i] = 0;
	    		}
	          phi[1]=1;
	    		for (int i = 2; i < MAX1; i++) {
	    			if (phi[i] == 0) {
	    				phi[i] = i - 1;

	    				for (int j = 2 * i; j < MAX1; j += i) {
	    					 if(phi[j]==0) phi[j] = j ;
	    					phi[j] -= (phi[j]/i);
	    				}
	    			}
	    		}

	    		for (int i = 1; i < MAX1; i++) {
	    			for (int j = i, k = 1; j < MAX1; j += i,k++) {
	    				phiSum[j] += i * phi[k];
	    			}
	    		}
	    		//System.out.println(Arrays.toString(phiSum));
                /*botharrays  res and phisum gives the same arrays so please don't worry*/

	    		for(int i=1;i<MAX1;i++)
	    		{
	    			for(int j=i+i;j<MAX1;j+=i)
	    			{
	    			   res[j]=res[j]+1L*i*phi[j/i];
	    			}
	    		}
	    		for(int i=1;i<=1000000;i++)
	    			res[i]=res[i]+res[i-1];
	    	//System.out.println(Arrays.toString(res));

	    }
	    public static void Seive()
		{
			l=new ArrayList<>();
			 b=new boolean[80001];
			Arrays.fill(b, true);
			b[0]=false;
			b[1]=false;

			for(int i=2;i<=(80000);i++)
			{
				if(b[i])
				{
					l.add(i);
				 for(int j=i*2;j<=80000;j+=i)
					{
						     b[j]=false;

					}
				}

			}

		}

	    private static class DSU{
			int[] parent;
			int[] rank;
			int cnt;
			public DSU(int n){
				parent=new int[n];
				rank=new int[n];
				for(int i=0;i<n;i++){
					parent[i]=i;
					rank[i]=1;
				}
				cnt=n;
			}
			int find(int i){
		        while(parent[i] !=i){
		        	parent[i]=parent[parent[i]];
		        	i=parent[i];
		        }
		        return i;
		    }
			int Union(int x, int y){
		        int xset = find(x);
		        int yset = find(y);
		        if(xset!=yset)
		        	cnt--;
		        if(rank[xset]<rank[yset]){
		        	parent[xset] = yset;
			        rank[yset]+=rank[xset];
			        rank[xset]=0;
			        return yset;
		        }else{
		        	parent[yset]=xset;
		        	rank[xset]+=rank[yset];
		        	rank[yset]=0;
		        	return xset;
		        }
		    }
		}
	  public static int[][] packU(int n, int[] from, int[] to, int max) {

		    int[][] g = new int[n][];
		    int[] p = new int[n];
		    for (int i = 0; i < max; i++) p[from[i]]++;
		    for (int i = 0; i < max; i++) p[to[i]]++;
		    for (int i = 0; i < n; i++) g[i] = new int[p[i]];
		    for (int i = 0; i < max; i++) {
		        g[from[i]][--p[from[i]]] = to[i];
		        g[to[i]][--p[to[i]]] = from[i];
		    }
		    return g;
		}
		public static int[][] parents3(int[][] g, int root) {
		    int n = g.length;
		    int[] par = new int[n];
		    Arrays.fill(par, -1);

		    int[] depth = new int[n];
		    depth[0] = 0;

		    int[] q = new int[n];
		    q[0] = root;
		    for (int p = 0, r = 1; p < r; p++) {
		        int cur = q[p];
		        for (int nex : g[cur]) {
		            if (par[cur] != nex) {
		                q[r++] = nex;
		                par[nex] = cur;
		                depth[nex] = depth[cur] + 1;
		            }
		        }
		    }
		    return new int[][]{par, q, depth};
		}
		public static int lower_bound(int[] nums, int target) {
	        int low = 0, high = nums.length - 1;
	        while (low < high) {
	            int mid = low + (high - low) / 2;
	            if (nums[mid] < target)
	                low = mid + 1;
	            else
	                high = mid;
	        }
	        return nums[low] == target ? low : -1;
	    }

	    public static int upper_bound(int[] nums, int target) {
	        int low = 0, high = nums.length - 1;
	        while (low < high) {
	            int mid = low + (high + 1 - low) / 2;
	            if (nums[mid] > target)
	                high = mid - 1;
	            else
	                low = mid;
	        }
	        return nums[low] == target ? low : -1;
	    }
	  public static boolean palin(String s)
		{
		   int i=0;
		   int j=s.length()-1;
		   while(i<j)
		   {
			   if(s.charAt(i)==s.charAt(j))
			   {
				   i++;
				   j--;
			   }
			   else return false;
		   }
		   return true;
		}

	    static boolean CountPs(String s,int n)
	       {
	    	boolean b=false;
	    	     char[] S=s.toCharArray();
		       int[][] dp=new int[n][n];
		       boolean[][] p=new boolean[n][n];
		       for(int i=0;i<n;i++)p[i][i]=true;

		       for(int i=0;i<n-1;i++)
		       {
		    	   if(S[i]==S[i+1])
		    	   {
		    		p[i][i+1]=true;
		    		dp[i][i+1]=1;
		    		b=true;
		    	   }
		       }

		       for(int gap=2;gap<n;gap++)
		       {
		    	   for(int i=0;i<n-gap;i++)
		    	   {
		    		   int j=gap+i;
		    		   if(S[i]==S[j]&&p[i+1][j-1]){p[i][j]=true;}

		    		  if(p[i][j])
		    			   dp[i][j]=dp[i][j-1]+dp[i+1][j]+1-dp[i+1][j-1];

		    		   else  dp[i][j]=dp[i][j-1]+dp[i+1][j]-dp[i+1][j-1];

		    		   if(dp[i][j]>=1){b=true;}
		    	   }
		       }

		    return b;
	   // return dp[0][n-1];

	    }

	public static int gcd(int a,int b)
	{
		int res=1;
		while(a>0)
		{
			res=a;
			a=b%a;
			b=res;
		}
		return res;
	}

	public static long pow(long n,long p,long m)
	{
		 long  result = 1;
		  if(p==0)
		    return 1;
		if (p==1)
		    return n;
		while(p!=0)
		{
		    if(p%2==1)
		        result *= n;
		    if(result>=m)
		    result%=m;
		    p >>=1;
		    n*=n;
		    if(n>=m)
		    n%=m;
		}
		return result;
	}

	static class Edge implements Comparator<Edge> {
		private int u;
		private int v;
		private int w;
		public Edge() {
		}
		public Edge(int u, int v, int w) {
			this.u=u;
			this.v=v;
			this.w=w;
		}
		public int getU() {
			return u;
		}
		public void setU(int u) {
			this.u = u;
		}
		public int getV() {
			return v;
		}
		public void setV(int v) {
			this.v = v;
		}
		public int getW() {
			return w;
		}
		public void setW(int w) {
			this.w = w;
		      }
		public int compareTo(Edge e)
		  {
			return this.getW() - e.getW();
		}
		@Override
		public String toString() {
			return "Edge [u=" + u + ", v=" + v + ", w=" + w + "]";
		}
		@Override
		public int compare(Edge arg0, Edge arg1) {
			// TODO Auto-generated method stub
			return 0;
		}
	}

	static class Pair implements Comparable<Pair>
	{
		int a,b;
		Pair (int a,int b)
		{
			this.a=a;
			this.b=b;
		}

		public int compareTo(Pair o) {
			// TODO Auto-generated method stub
			if(this.a!=o.a)
			return -Integer.compare(this.a,o.a);
			else
				return -Integer.compare(this.b, o.b);
			//return 0;
		}
		public boolean equals(Object o) {
	       if (o instanceof Pair) {
	           Pair p = (Pair)o;
	           return p.a == a && p.b == b;
	       }
	       return false;
	   }
	   public int hashCode() {
	       return new Integer(a).hashCode() * 31 + new Integer(b).hashCode();
	   }
	}

		static class InputReader
		{
			private InputStream stream;
			private byte[] buf = new byte[1024];
			private int curChar;
			private int numChars;
			private SpaceCharFilter filter;

			public InputReader(InputStream stream)
			{
				this.stream = stream;
			}

			public int read()
			{
				if (numChars==-1)
					throw new InputMismatchException();

				if (curChar >= numChars)
				{
					curChar = 0;
					try
					{
						numChars = stream.read(buf);
					}
					catch (IOException e)
					{
						throw new InputMismatchException();
					}

					if(numChars <= 0)
						return -1;
				}
				return buf[curChar++];
			}

			public String nextLine()
			{
				BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
				String str = "";
	            try
	            {
	                str = br.readLine();
	            }
	            catch (IOException e)
	            {
	                e.printStackTrace();
	            }
	            return str;
			}
			public int ii()
			{
				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 long il()
			{
				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 double nextDouble()
			{
				int c = read();
				while (isSpaceChar(c))
					c = read();
				int sgn = 1;
				if (c == '-')
				{
					sgn = -1;
					c = read();
				}
				double res = 0;
				while (!isSpaceChar(c) && c != '.')
				{
					if (c == 'e' || c == 'E')
						return res * Math.pow(10, ii());
					if (c < '0' || c > '9')
						throw new InputMismatchException();
					res *= 10;
					res += c - '0';
					c = read();
				}
				if (c == '.')
				{
					c = read();
					double m = 1;
					while (!isSpaceChar(c))
					{
						if (c == 'e' || c == 'E')
							return res * Math.pow(10, ii());
						if (c < '0' || c > '9')
							throw new InputMismatchException();
						m /= 10;
						res += (c - '0') * m;
						c = read();
					}
				}
				return res * sgn;
			}

			public String readString()
			{
				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 boolean isSpaceChar(int c)
			{
				if (filter != null)
					return filter.isSpaceChar(c);
				return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
			}

			public String next()
			{
				return readString();
			}

			public interface SpaceCharFilter
			{
				public boolean isSpaceChar(int ch);
			}
		}
	}


///package CodeForce;
import java.io.*;
import java.util.*;
/**
 *
 * @author prabhat
 */
public class P400A {

	   static final int MAX1 = 1000000+10;
	   static final long mod = 1000000007;
	   static final long MOD = 100000000000000007L;
	   static int phiSum[] = new int[MAX1];
	   static int phi[] = new int[MAX1];
	   static long[] res=new long[MAX1];
	   static int a[];
	   static long BIT[];
	   static int n,m,k,p;
	   static boolean[] b;
	   static long[][] pascal;
           static long[][] dp;
           static LinkedList<Integer> list[];
           static ArrayList<Integer> l;
           static TreeSet<Integer> ts;
           static int max=1<<11;
           static char[] s;
	    public static void main(String[] args) throws IOException{

	        InputReader in = new InputReader(System.in);
               //BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
	        PrintWriter pw = new PrintWriter(System.out,true);
              int t=in.ii();
              while(t-->0)
              {
                s=in.next().trim().toCharArray();
               ts=new TreeSet<>();
                for(int i=1;i<=12;i++)
                {
                   if(12%i==0)
                   {
                      if(sol(i,12/i))
                          ts.add(i);
                   }
                }
                pw.print(ts.size()+" ");
                for(int o:ts)
                    pw.print(o+"X"+(12/o)+" ");
                pw.println();
              }

	      pw.close();
	    }
         static boolean sol(int a,int b)
            {
               boolean res=false;
               for(int c=0;c<b;c++)
               {
                  boolean f=true;
                  for(int r=0;r<a;r++)
                  {
                    f&=(s[r*b+c]=='X');
                  }
                  res|=f;
               }
            return res;
            }
            static void pascal()
	    {
	  	  pascal=new long[max][max];
	  	  for(int i=0;i<max;i++)
	  	  {
	  		  pascal[i][0]=1L;
	  		  for(int j=1;j<=i;j++)
	  		  {
	  			  pascal[i][j]=(int) ((pascal[i-1][j]+pascal[i-1][j-1])%mod);
	  		  }
	  	  }

	    }
       public static long pow(long n,long p)
	{
		long  result = 1L;
		  if(p==0)
		    return 1L;
		if (p==1)
		    return n;
		while(p!=0)
		{
		    if(p%2==1)
		        result *= n;
		    p >>=1;
		    n*=n;
		}
		return result;

	}

    boolean nextPermutation(int[] p) {
        for (int a = p.length - 2; a >= 0; --a)
        {
            if (p[a] < p[a + 1])
                for (int b = p.length - 1; ; --b)
                    if (p[b] > p[a]) {
                        int t = p[a];
                        p[a] = p[b];
                        p[b] = t;
                        for (++a, b = p.length - 1; a < b; ++a, --b)
                        {
                            t = p[a];
                            p[a] = p[b];
                            p[b] = t;
                        }
                        return true;
                    }
        }
        return false;
     }

	    public static long nCr(long total, long choose)
		{
			if(total < choose)
				return 0;
			if(choose == 0 || choose == total)
				return 1;
			return nCr(total-1,choose-1)+nCr(total-1,choose);
		}
	    static void compute() {
	    		for (int i = 0; i < MAX1; i++) {
	    			phi[i] = 0;
	    		}
	          phi[1]=1;
	    		for (int i = 2; i < MAX1; i++) {
	    			if (phi[i] == 0) {
	    				phi[i] = i - 1;

	    				for (int j = 2 * i; j < MAX1; j += i) {
	    					 if(phi[j]==0) phi[j] = j ;
	    					phi[j] -= (phi[j]/i);
	    				}
	    			}
	    		}

	    		for (int i = 1; i < MAX1; i++) {
	    			for (int j = i, k = 1; j < MAX1; j += i,k++) {
	    				phiSum[j] += i * phi[k];
	    			}
	    		}
	    		//System.out.println(Arrays.toString(phiSum));
                /*botharrays  res and phisum gives the same arrays so please don't worry*/

	    		for(int i=1;i<MAX1;i++)
	    		{
	    			for(int j=i+i;j<MAX1;j+=i)
	    			{
	    			   res[j]=res[j]+1L*i*phi[j/i];
	    			}
	    		}
	    		for(int i=1;i<=1000000;i++)
	    			res[i]=res[i]+res[i-1];
	    	//System.out.println(Arrays.toString(res));

	    }
	    public static void Seive()
		{
			l=new ArrayList<>();
			 b=new boolean[80001];
			Arrays.fill(b, true);
			b[0]=false;
			b[1]=false;

			for(int i=2;i<=(80000);i++)
			{
				if(b[i])
				{
					l.add(i);
				 for(int j=i*2;j<=80000;j+=i)
					{
						     b[j]=false;

					}
				}

			}

		}

	    private static class DSU{
			int[] parent;
			int[] rank;
			int cnt;
			public DSU(int n){
				parent=new int[n];
				rank=new int[n];
				for(int i=0;i<n;i++){
					parent[i]=i;
					rank[i]=1;
				}
				cnt=n;
			}
			int find(int i){
		        while(parent[i] !=i){
		        	parent[i]=parent[parent[i]];
		        	i=parent[i];
		        }
		        return i;
		    }
			int Union(int x, int y){
		        int xset = find(x);
		        int yset = find(y);
		        if(xset!=yset)
		        	cnt--;
		        if(rank[xset]<rank[yset]){
		        	parent[xset] = yset;
			        rank[yset]+=rank[xset];
			        rank[xset]=0;
			        return yset;
		        }else{
		        	parent[yset]=xset;
		        	rank[xset]+=rank[yset];
		        	rank[yset]=0;
		        	return xset;
		        }
		    }
		}
	  public static int[][] packU(int n, int[] from, int[] to, int max) {

		    int[][] g = new int[n][];
		    int[] p = new int[n];
		    for (int i = 0; i < max; i++) p[from[i]]++;
		    for (int i = 0; i < max; i++) p[to[i]]++;
		    for (int i = 0; i < n; i++) g[i] = new int[p[i]];
		    for (int i = 0; i < max; i++) {
		        g[from[i]][--p[from[i]]] = to[i];
		        g[to[i]][--p[to[i]]] = from[i];
		    }
		    return g;
		}
		public static int[][] parents3(int[][] g, int root) {
		    int n = g.length;
		    int[] par = new int[n];
		    Arrays.fill(par, -1);

		    int[] depth = new int[n];
		    depth[0] = 0;

		    int[] q = new int[n];
		    q[0] = root;
		    for (int p = 0, r = 1; p < r; p++) {
		        int cur = q[p];
		        for (int nex : g[cur]) {
		            if (par[cur] != nex) {
		                q[r++] = nex;
		                par[nex] = cur;
		                depth[nex] = depth[cur] + 1;
		            }
		        }
		    }
		    return new int[][]{par, q, depth};
		}
		public static int lower_bound(int[] nums, int target) {
	        int low = 0, high = nums.length - 1;
	        while (low < high) {
	            int mid = low + (high - low) / 2;
	            if (nums[mid] < target)
	                low = mid + 1;
	            else
	                high = mid;
	        }
	        return nums[low] == target ? low : -1;
	    }

	    public static int upper_bound(int[] nums, int target) {
	        int low = 0, high = nums.length - 1;
	        while (low < high) {
	            int mid = low + (high + 1 - low) / 2;
	            if (nums[mid] > target)
	                high = mid - 1;
	            else
	                low = mid;
	        }
	        return nums[low] == target ? low : -1;
	    }
	  public static boolean palin(String s)
		{
		   int i=0;
		   int j=s.length()-1;
		   while(i<j)
		   {
			   if(s.charAt(i)==s.charAt(j))
			   {
				   i++;
				   j--;
			   }
			   else return false;
		   }
		   return true;
		}

	    static boolean CountPs(String s,int n)
	       {
	    	boolean b=false;
	    	     char[] S=s.toCharArray();
		       int[][] dp=new int[n][n];
		       boolean[][] p=new boolean[n][n];
		       for(int i=0;i<n;i++)p[i][i]=true;

		       for(int i=0;i<n-1;i++)
		       {
		    	   if(S[i]==S[i+1])
		    	   {
		    		p[i][i+1]=true;
		    		dp[i][i+1]=1;
		    		b=true;
		    	   }
		       }

		       for(int gap=2;gap<n;gap++)
		       {
		    	   for(int i=0;i<n-gap;i++)
		    	   {
		    		   int j=gap+i;
		    		   if(S[i]==S[j]&&p[i+1][j-1]){p[i][j]=true;}

		    		  if(p[i][j])
		    			   dp[i][j]=dp[i][j-1]+dp[i+1][j]+1-dp[i+1][j-1];

		    		   else  dp[i][j]=dp[i][j-1]+dp[i+1][j]-dp[i+1][j-1];

		    		   if(dp[i][j]>=1){b=true;}
		    	   }
		       }

		    return b;
	   // return dp[0][n-1];

	    }

	public static int gcd(int a,int b)
	{
		int res=1;
		while(a>0)
		{
			res=a;
			a=b%a;
			b=res;
		}
		return res;
	}

	public static long pow(long n,long p,long m)
	{
		 long  result = 1;
		  if(p==0)
		    return 1;
		if (p==1)
		    return n;
		while(p!=0)
		{
		    if(p%2==1)
		        result *= n;
		    if(result>=m)
		    result%=m;
		    p >>=1;
		    n*=n;
		    if(n>=m)
		    n%=m;
		}
		return result;
	}

	static class Edge implements Comparator<Edge> {
		private int u;
		private int v;
		private int w;
		public Edge() {
		}
		public Edge(int u, int v, int w) {
			this.u=u;
			this.v=v;
			this.w=w;
		}
		public int getU() {
			return u;
		}
		public void setU(int u) {
			this.u = u;
		}
		public int getV() {
			return v;
		}
		public void setV(int v) {
			this.v = v;
		}
		public int getW() {
			return w;
		}
		public void setW(int w) {
			this.w = w;
		      }
		public int compareTo(Edge e)
		  {
			return this.getW() - e.getW();
		}
		@Override
		public String toString() {
			return "Edge [u=" + u + ", v=" + v + ", w=" + w + "]";
		}
		@Override
		public int compare(Edge arg0, Edge arg1) {
			// TODO Auto-generated method stub
			return 0;
		}
	}

	static class Pair implements Comparable<Pair>
	{
		int a,b;
		Pair (int a,int b)
		{
			this.a=a;
			this.b=b;
		}

		public int compareTo(Pair o) {
			// TODO Auto-generated method stub
			if(this.a!=o.a)
			return -Integer.compare(this.a,o.a);
			else
				return -Integer.compare(this.b, o.b);
			//return 0;
		}
		public boolean equals(Object o) {
	       if (o instanceof Pair) {
	           Pair p = (Pair)o;
	           return p.a == a && p.b == b;
	       }
	       return false;
	   }
	   public int hashCode() {
	       return new Integer(a).hashCode() * 31 + new Integer(b).hashCode();
	   }
	}

		static class InputReader
		{
			private InputStream stream;
			private byte[] buf = new byte[1024];
			private int curChar;
			private int numChars;
			private SpaceCharFilter filter;

			public InputReader(InputStream stream)
			{
				this.stream = stream;
			}

			public int read()
			{
				if (numChars==-1)
					throw new InputMismatchException();

				if (curChar >= numChars)
				{
					curChar = 0;
					try
					{
						numChars = stream.read(buf);
					}
					catch (IOException e)
					{
						throw new InputMismatchException();
					}

					if(numChars <= 0)
						return -1;
				}
				return buf[curChar++];
			}

			public String nextLine()
			{
				BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
				String str = "";
	            try
	            {
	                str = br.readLine();
	            }
	            catch (IOException e)
	            {
	                e.printStackTrace();
	            }
	            return str;
			}
			public int ii()
			{
				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 long il()
			{
				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 double nextDouble()
			{
				int c = read();
				while (isSpaceChar(c))
					c = read();
				int sgn = 1;
				if (c == '-')
				{
					sgn = -1;
					c = read();
				}
				double res = 0;
				while (!isSpaceChar(c) && c != '.')
				{
					if (c == 'e' || c == 'E')
						return res * Math.pow(10, ii());
					if (c < '0' || c > '9')
						throw new InputMismatchException();
					res *= 10;
					res += c - '0';
					c = read();
				}
				if (c == '.')
				{
					c = read();
					double m = 1;
					while (!isSpaceChar(c))
					{
						if (c == 'e' || c == 'E')
							return res * Math.pow(10, ii());
						if (c < '0' || c > '9')
							throw new InputMismatchException();
						m /= 10;
						res += (c - '0') * m;
						c = read();
					}
				}
				return res * sgn;
			}

			public String readString()
			{
				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 boolean isSpaceChar(int c)
			{
				if (filter != null)
					return filter.isSpaceChar(c);
				return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
			}

			public String next()
			{
				return readString();
			}

			public interface SpaceCharFilter
			{
				public boolean isSpaceChar(int ch);
			}
		}
	}