# Arup Guha
# 3/24/2026
# Solution to Practice Problem: Conference.

# Go through cases.
nC = int(input())
for loop in range(nC):

    # days[i] will store length of conference on day i.
    days = []
    for j in range(30):
        days.append(0)

    # Loop through potential conferences.
    n = int(input())
    for j in range(n):

        # Update the longest conference starting on this day.
        toks = input().split()
        start = int(toks[0])
        length = int(toks[1])
        days[start] = max(days[start], length)

    # Store answer here.
    res = 0
    canDo = 0

    # Just go through days.
    for i in range(len(days)):

        # We should add this conference.
        if days[i] > 0 and i>=canDo:

            # Add up all the money we get for it.
            for j in range(days[i]):
                res += (1<<(29-i-j))

            # Update when we are free.
            canDo = i+days[i]

    # Ta da!
    print(res)
