# Arup Guha
# 3/6/2026
# Solution to COP 4516 Team Final Contest Problem: Perplexing Puzzle

def go(n, tot):

    # Base case.
    if n == 0:
        if tot == 0:
            return 1
        return 0

    # If n>0, tot can't be 0.
    if tot < 0:
        return 0

    # Pick 1,2 or 3 and recurse.
    return go(n-1, tot) + go(n-1, tot-1) + go(n-1, tot-2) + go(n-1, tot-3)
    
# Process cases.
nC = int(input())
for loop in range(nC):
    toks = input().split()
    print(go(int(toks[0]), int(toks[1])))

