#include #include using namespace std; int d[50]; int minh[50][1010]; char move[50][1010]; /* * minh[i][h] = lowest max height above ground to be at height h * after distances d[0]..d[i] * * move[i][h] = move to make for distance d[i] to end up at h in * while achieving minh[i][h] */ const int infty = 1000000000; void solve() { int m; cin >> m; int tot = 0; for (int i = 0; i < m; ++i) { cin >> d[i]; tot += d[i]; } for (int i = 0; i < m; ++i) for (int j = 0; j <= tot; ++j) minh[i][j] = infty; minh[0][d[0]] = d[0]; move[0][d[0]] = 'U'; for (int i = 1; i < m; ++i) for (int h = 0; h <= tot; ++h) { if (minh[i-1][h] != infty) { if (h >= d[i]) { // try climbing down if (minh[i][h-d[i]] > minh[i-1][h]) { minh[i][h-d[i]] = minh[i-1][h]; move[i][h-d[i]] = 'D'; } } // try climbing up int newminh = max(minh[i-1][h], h+d[i]); if (minh[i][h+d[i]] > newminh) { minh[i][h+d[i]] = newminh; move[i][h+d[i]] = 'U'; } } } if (minh[m-1][0] == infty) cout << "IMPOSSIBLE" << endl; else { char s[100]; s[m] = 0; int h = 0; for (int i = m-1; i >= 0; --i) { s[i] = move[i][h]; if (s[i] == 'U') h -= d[i]; else h += d[i]; } cout << s << endl; } } int main() { int n; for (cin >> n; n > 0; --n) solve(); return 0; }