#include #include #include using namespace std; main() { int loop; cin >> loop; while (loop--){ int r; vector > graph(101); vector edge(101); edge[0] = 1; vector path; path.push_back(0); int index = 1; while (cin >> r && r){ if (r > 0){ while (edge[path.back()] == 0){ path.pop_back(); } graph[path.back()].insert(index); graph[index].insert(path.back()); --edge[path.back()]; edge[index] = r - 1; path.push_back(index); ++index; while (edge[path.back()] == 0){ path.pop_back(); } } else { while (edge[path.back()] == 0){ path.pop_back(); } graph[path.back()].insert(path[path.size() + r - 1]); graph[path[path.size() + r - 1]].insert(path.back()); --edge[path.back()]; --edge[path[path.size() + r - 1]]; while (edge[path.back()] == 0){ path.pop_back(); } } } index = 1; while (!graph[index].empty()){ cout << index; for (multiset::iterator it = graph[index].begin(); it != graph[index].end(); ++it){ if (*it == 0){ continue; } cout << " " << *it; } cout << endl; ++index; } } }