#include <iostream>
#include <vector>
#include <algorithm>
#include <random>

using namespace std;

mt19937 r_dev;
mt19937_64 r_dev64;
// Returns a value in range [0, 1[
double rnd()
{
    return uniform_real_distribution<double>(0, 1)(r_dev);
}
// Returns a value in range [a, b] inclusive
int rnd(int a, int b)
{
    return uniform_int_distribution<int>(a, b)(r_dev);
}
long long rnd64(long long a, long long b)
{
    return uniform_int_distribution<long long>(a, b)(r_dev64);
}
// Returns either 0 or 1
int coin()
{
    return rnd(0, 1);
}
// Shuffles any type with begin and end
template <typename T>
void shuffle(T &arr)
{
    shuffle(arr.begin(), arr.end(), r_dev);
}

int main(int argc, char **argv)
{
    // Check argument count
    if (argc <= 3) {
        cerr << "Expected: ./generator seed n ..." << endl;
        exit(1);
    }

    // Parse arguments into numbers
    unsigned long long seed = stoull(argv[1]);
    r_dev.seed(seed);
    r_dev64.seed(seed);
    int t = atoi(argv[2]);
    int n = atoi(argv[3]);

    if (seed == 0) {
        bool first = true;
        for (int i = 2; i < argc; i++) {
            if (argv[i][0] == 'N') {
                first = true;
                cout<<endl;
            } else {
                if (!first) cout<<" ";
                first = false;
                cout<<argv[i];
            }
        }
        return 0;
    }

    cout<<t<<endl;
    for (int tt = 0; tt < t; tt++) {
        int colors[n];
        for (int i = 0; i < n; i++) {
            colors[i] = 0;
        }
        int pos = 0;
        int argi = 4;
        int color = 1;
        while (pos < n) {
            char c = argv[argi++][0];
            if (c == 'F') {
                int cnt = atoi(argv[argi++]);
                while (cnt) {
                    colors[pos++] = color;
                    cnt--;
                }
                color++;
            } else if (c == 'X') {
                int cnt = atoi(argv[argi++]);
                int times = atoi(argv[argi++]);
                while (times) {
                    for (int x = 0; x < cnt; x++) {
                        colors[pos++] = color;
                    }
                    times--;
                    color++;
                }
            } else if (c == 'R') {
                int range = atoi(argv[argi++]);
                while (pos < n) {
                    colors[pos++] = rnd(color, color + range - 1);
                }
            } else {
                cerr<<"Expected: ./generator seed n ... F count or R range or X count times"<<endl;
                cerr<<"F count repeats color count times"<<endl;
                cerr<<"R range fills the rest with random colors in range [color, color + range)"<<endl;
                cerr<<"X count times is a shorthand for F count ... F count"<<endl;
                exit(1);
            }
        }

        vector<int> color_map(n+1);
        int k = 0;
        for (int c : colors) {
            if (!color_map[c]) {
                color_map[c] = ++k;
            }
        }

        vector<int> color_p(k);
        for (int i = 0; i < k; i++) color_p[i] = i + 1;
        if (seed) {
            shuffle(colors, colors + n, r_dev);
            shuffle(color_p);
        }

        cout<<n<<" "<<k<<endl;
        for (int i = 0; i < n; i++) {
            if (i) cout<<" ";
            cout<<color_p[color_map[colors[i]] - 1];
        }
        cout<<endl;
    }
}
