for _ in [0]*eval(input()):

  A = '012345678954321'

  a, b = input().split()

  n = 15

  for _ in [0]*A.count(a):

    I = A.index(a)

    A = A[I:]+A[:I]

    I = A.index(b)

    if n>I:

      n = I

      x = A[:I+1]

    A = A[1:]+A[0]

  for e in x:

    print(e, end=' ')

  print()
for _ in [0]*eval(input()):

  A = "012345678954321"

  a, b = input().split()

  n = 15

  for _ in [0]*A.count(a):

    I = A.index(a)

    A = A[I:]+A[:I]

    I = A.index(b)

    if n>I:

      n = I

      x = A[:I+1]

    A = A[1:]+A[0]

  print(" ".join(x))
for _ in [0] * eval(input()):
    A = "012345678954321"
    a, b = input().split()
    n = 15
    for _ in [0] * A.count(a):
        I = A.index(a)
        A = A[I:] + A[:I]
        I = A.index(b)
        if n > I:
            n = I
            x = A[: I + 1]
        A = A[1:] + A[0]
    for e in x:
        print(e, end=" ")
    print()

for _ in [0] * eval(input()):
    A = "012345678954321"
    a, b = input().split()
    n = 15
    for _ in [0] * A.count(a):
        I = A.index(a)
        A = A[I:] + A[:I]
        I = A.index(b)
        if n > I:
            n = I
            x = A[: I + 1]
        A = A[1:] + A[0]
    print(" ".join(x))

-    for e in x: -        print(e, end=" ") -    print() +    print(" ".join(x))