// Arup Guha
// 7/21/2014
// Solution to 2004 MCPC Problem D: Flow Layout
import java.util.*;

public class d {

    public static void main(String[] args) {

        Scanner stdin = new Scanner(System.in);
        int n = stdin.nextInt();
        int loop = 1;

        // Go through all cases.
        while (n != 0) {

            // Start all necessary counters.
            int width = stdin.nextInt();
            int height = stdin.nextInt();
            int curW = 0, curH = 0, maxRowH = 0, maxW = 0;

            // Go through each window.
            while (width != -1) {

                // Stay on the same row.
                if (width + curW <= n) {
                    curW += width;
                    maxW = Math.max(maxW, curW);
                    maxRowH = Math.max(maxRowH, height);
                }

                // Put this box as the first on the next row.
                else {
                    curW = width;
                    curH += maxRowH;
                    maxRowH = height;
                }

                // Get next.
                width = stdin.nextInt();
                height = stdin.nextInt();
            }

            // Output and go to next case.
            System.out.println(maxW+" x "+(curH+maxRowH));
            n = stdin.nextInt();
        }
    }
}
