#include using namespace std; #define tsolve int t; cin >> t; while (t--) solve #define all(x) ::begin(x), ::end(x) #define sz(x) (ll)::size(x) using ll = long long; using ld = long double; ll n; vector c, p; bool solve_part(vector& res) { ll curc = n; for (ll i = 0; i < n; ++i) { if (c[i] == '-' && p[i] != '-') { curc = i; break; } } if (curc == n) { return false; } ll curp = p[curc]; p[curc] = '-'; res.push_back("DRIVE " + to_string(curc + 1)); bool t = true; while (t) { t = false; for (ll i = 0; i < n; ++i) { if (c[i] == curp && p[i] != curp && p[i] != '-') { res.push_back("PICKUP"); res.push_back("DRIVE " + to_string(i + 1)); res.push_back("DROPOFF"); curp = p[i]; p[i] = c[i]; t = true; break; } } if (t) continue; for (ll i = 0; i < n; ++i) { if (c[i] == curp && p[i] == '-') { res.push_back("PICKUP"); res.push_back("DRIVE " + to_string(i + 1)); res.push_back("DROPOFF"); curp = p[i]; p[i] = c[i]; return true; } } } return true; } void solve() { cin >> n; c.resize(n); for (char& x : c) cin >> x; p.resize(n); for (char& x : p) cin >> x; vector res; while (solve_part(res)); cout << ssize(res) << '\n'; for (string x : res) cout << x << '\n'; } int main() { cin.tie(0)->sync_with_stdio(false); cout << setprecision(16); solve(); }