human
An old document says that a Ninja House in Kanazawa City was in fact a defensive fortress, which was designed like a maze. Its rooms were connected by hidden doors in a complicated manner, so that any invader would become lost. Each room has at least two doors.

The Ninja House can be modeled by a graph, as shown in Figure l. A circle represents a room. Each line connecting two circles represents a door between two rooms.

 Figure l. Graph Model of Ninja House.  |  Figure 2. Ninja House exploration.
---|---

I decided to draw a map, since no map was available. Your mission is to help me draw a map from the record of my exploration.

I started exploring by entering a single entrance that was open to the outside. The path I walked is schematically shown in Figure 2, by a line with arrows. The rules for moving between rooms are described below.

After entering a room, I first open the rightmost door and move to the next room. However, if the next room has already been visited, I close the door without entering, and open the next rightmost door, and so on. When I have inspected all the doors of a room, I go back through the door I used to enter the room.

I have a counter with me to memorize the distance from the first room. The counter is incremented when I enter a new room, and decremented when I go back from a room. In Figure 2, each number in parentheses is the value of the counter when I have entered the room, i.e., the distance from the first room. In contrast, the numbers not in parentheses represent the order of my visit.

I take a record of my exploration. Every time I open a door, I record a single number, according to the following rules.

1. If the opposite side of the door is a new room, I record the number of doors in that room, which is a positive number.
2. If it is an already visited room, say R, I record ``the distance of R from the first room'' minus ``the distance of the current room from the first room'', which is a negative number.


In the example shown in Figure 2, as the first...
assistant
#Here is the Python program you requested.

import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**13
mod = 10**9+7
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)

def main():
    rr = []

    def f():
        a = LI()
        while a[-1] != 0:
            a += LI()
        r = [[]]
        c = 0
        nk = [a[0]]
        d = {}
        d[0] = 0
        for n in a[1:]:
            if n == 0:
                break
            while nk[d[c]] < 1:
                c -= 1

            if n < 0:
                dc = d[c]
                dn = d[c+n]
                r[dn].append(dc)
                r[dc].append(dn)
                nk[dn] -= 1
                nk[dc] -= 1
            else:
                nk.append(n-1)
                dc = d[c]
                ni = len(nk) - 1
                r[dc].append(ni)
                r.append([dc])
                nk[dc] -= 1
                c += 1
                d[c] = ni
        rr = []
        for i in range(len(nk)):
            rr.append('{} {}'.format(i+1, ' '.join(map(lambda x: str(x+1), sorted(r[i])))))
        return '\n'.join(rr)

    while 1:
        n = I()
        if n == 0:
            break
        rr = [f() for _ in range(n)]
        break

    return '\n'.join(map(str, rr))

print(main())