/* clang-format off */
#include "testlib.h"
#include "limits.h"
#include <bits/stdc++.h>
/* clang-format on */

using namespace std;

int main(int argc, char *argv[]) {
    registerValidation(argc, argv);

    int group = atoi(validator.group().c_str());
    const auto limits = LIMITS[group];

    int n = inf.readInt(2, limits.max_n, "n");
    inf.readSpace();
    int m = inf.readInt(2, limits.max_m, "m");
    inf.readEoln();

    string path = inf.readToken("[UDR]{1," + vtos(2 * n * m) + "}", "path");
    inf.readEoln();

    vector<string> a(n);
    for (int i = 0; i < n; i++) {
        a[i] = inf.readToken("[.#]{" + vtos(m) + "," + vtos(m) + "}", "a[" + vtos(i + 1) + "]");
        inf.readEoln();
    }
    inf.readEof();

    for (auto c : path) {
        bool failed = false;
        failed |= c == 'R' && !limits.allow_right;
        failed |= c == 'D' && !limits.allow_down;
        failed |= c == 'U' && !limits.allow_up;
        ensuref(!failed, "in group %d path can not contain %c", group, c);
    }
}
