# Python solution to "Lego Ramp" from 2025 CS@UCF

test_count = int(input())

for _ in range(test_count):
    level_count = int(input())

    valid = True

    above = [int(input())]

    for level in range(1, level_count):
        index = 0
        below = []
        for brick in map(int, input().split()):
            below.append(brick)
            if(index > 0 and (below[index - 1] + brick) < above[index - 1]):
                valid = False
            index += 1
        above = below
    if(valid):
        print("stable")
    else:
        print("unstable")

