#include #include #include #include #include using namespace std; struct Node { Node *l, *r; int size, d; } b[212345]; int cnt; Node *newnode(int d) { b[cnt].l = b[cnt].r = nullptr; b[cnt].size = 1; b[cnt].d = d; return &b[cnt++]; } Node *merge(Node *a, Node *b) { Node *r = newnode(a->d - 1); r->size = a->size + b->size; r->l = a; r->r = b; return r; } vector ans; void dfs(Node *x, int base) { if (x == nullptr || x->l == nullptr) return; ans.push_back(base + x->l->size); dfs(x->l, base); dfs(x->r, base + x->l->size); } void solve() { int n; cin >> n; vector a(n); for (int i = 0; i < n; ++i) { cin >> a[i]; } cnt = 0; vector s; for (int i = 0; i < n; ++i) { s.push_back(newnode(a[i])); while (s.size() >= 2 && s.back()->d == s[s.size() - 2]->d) { Node *r = s.back(); s.pop_back(); Node *l = s.back(); s.pop_back(); s.push_back(merge(l, r)); } } if (s.size() != 1 || s.back()->d != 0) { cout << "Impossible" << endl; return; } cout << "Possible" << endl; ans.clear(); dfs(s.back(), 0); for (size_t i = 0; i < ans.size(); ++i) { cout << ans[i] << (i + 1 == ans.size() ? '\n' : ' '); } } int main() { ios::sync_with_stdio(false); int T; cin >> T; while (T-- > 0) { solve(); } return 0; }