#include using namespace std; using ll = long long; using ld = long double; using pii = pair; using vi = vector; using vvi = vector; #define rep(i, a, b) for(ll i = (a); i < (b); i++) #define all(x) begin(x),end(x) #define sz(x) (int)(x).size() void solve() { ll n; string c, p; cin >> n >> c >> p; vvi types(6); rep(i,0,n) { #define gah(c1, c2, t0) if (c[i] == c1 && p[i] == c2) types[t0].push_back(i + 1); gah('M', 'C', 0) gah('C', 'M', 1) gah('-', 'C', 2) gah('-', 'M', 3) gah('M', '-', 4) gah('C', '-', 5) } vector total; rep(i, 0, 2) { while (!empty(types[4 + i])) { ll z = types[4 + i].back(); types[4 + i].pop_back(); vector> ops; ops.push_back({"DRIVE " + to_string(z), "DROPOFF"}); ll nx = !i; while (!empty(types[nx])) { auto zz = types[nx].back(); types[nx].pop_back(); ops.push_back({"DRIVE " + to_string(zz), "DROPOFF", "PICKUP"}); nx ^= 1; } nx = 2 + nx; ops.push_back({"DRIVE " + to_string(types[nx].back()), "PICKUP"}); types[nx].pop_back(); reverse(all(ops)); for (auto& x : ops) for (auto& y : x) total.push_back(y); } } ll first = sz(types[0]) > sz(types[1]) ? 0 : sz(types[0]) < sz(types[1]) ? 1 : empty(types[2]) ? 1 : 0; // sus for (ll i : {first, 1 - first}) { while (!empty(types[i])) { ll z = types[i].back(); types[i].pop_back(); vector> ops; ops.push_back({"DRIVE " + to_string(z), "DROPOFF"}); ll nx = !i; while (!empty(types[nx])) { auto zz = types[nx].back(); types[nx].pop_back(); ops.push_back({"DRIVE " + to_string(zz), "DROPOFF", "PICKUP"}); nx ^= 1; } nx = 2 + nx; ops.push_back({"DRIVE " + to_string(types[nx].back()), "PICKUP"}); types[nx].pop_back(); reverse(all(ops)); for (auto& x : ops) for (auto& y : x) total.push_back(y); } } cout << ssize(total) << "\n"; for (auto& x : total) cout << x << '\n'; } int main() { cin.tie(0)->sync_with_stdio(0); cin.exceptions(cin.failbit); //ll t; cin >> t; while(t--) solve(); }