Print all subarrays of a given array

If your issue is that you have empty lines, simplify your code to directly slice the list will all needed items.

You can use unpacking in print to have space separated elements by default.

t = int(input())
for z in range(t):
    n = int(input()) 
    a = list(map(int, input().split()))  

    for i in range(n):
        for j in range(i+1,n+1):
            print(*a[i:j])

input/ouput:

1
3
1 2 3  # end of input
1
1 2
1 2 3
2
2 3
3