import java.io.File;
import java.io.FileNotFoundException;
import java.io.PrintWriter;
import java.util.Locale;
import java.util.Random;
import java.util.Scanner;


public class TestsGen implements Runnable {
    private static final int MIN_POW = 5;
    private static final int MAX_POW = 100;

    private Scanner in;
    private int testId;
    private PrintWriter out;

    int[] primes;
    int primesCnt;
    {
        primes = new int[MAX_POW];   
        primesCnt = 0;
outer:
        for (int i = MIN_POW; i <= MAX_POW; i++) {
            for (int j = 2; j * j <= i; j++) {
                if (i % j == 0) {
                    continue outer;
                }
            } 
            primes[primesCnt++] = i;
        }
    }
    Random random = new Random(20080209);
    
    private boolean generateTest() throws FileNotFoundException {
        if (!in.hasNext()) {
            return false;
        }
        out = new PrintWriter(String.format("%d%d", testId / 10, testId % 10));
        int pow;
        int mod;
        int len;
        int val;
        String str = in.next();
        if ("random".equals(str)) {
            len = in.nextInt();
            mod = 1 << random.nextInt(9);
            pow = primes[random.nextInt(primesCnt)];
            val = random.nextInt(mod);
        } else {
            pow = Integer.parseInt(str);
            mod = in.nextInt();
            len = in.nextInt();
            val = in.nextInt();
        }
        out.println(pow + " " + mod + " " + len + " " + val);
        out.close();
        return true;
    }

    public TestsGen(int test, String file) {
        System.out.printf("Generating tests from file '%s' starting from test #%d\n", file, test);
        try {
            testId = test;
            in = new Scanner(new File(file));
        } catch (FileNotFoundException e) {
            apstenu(e);
        }
    }

    public void run() {
        try {
            while (generateTest()) {
                testId++;
            }
        } catch (FileNotFoundException e) {
            apstenu(e);
        }
    }

    private void apstenu(Exception e) {
        e.printStackTrace();
        System.exit(1);
    }

    public static void main(String[] args) {
        Locale.setDefault(Locale.US);
        new Thread(new TestsGen(Integer.parseInt(args[0]), args[1])).start();
    }
}
