from collections import defaultdict, deque

def find_max_length(t, test_cases):
    results = []
    
    for n, a in test_cases:
        b = [a[i] + i for i in range(n)]  # b[i] = a[i] + (i + 1)
        c = [b[i] + i for i in range(n)]  # c[i] = b[i] + (i + 1)
        
        u = [(b[i], i) for i in range(n)]  # Pair (b[i], i)
        v = [(c[i], i) for i in range(n)]  # Pair (c[i], i)

        # Sort both u and v based on the first element of the pair
        u.sort()
        v.sort()

        # Use two pointers to find pairs (i, j) such that u[i].first == v[j].first
        graph = defaultdict(list)
        
        i, j = 0, 0
        while i < n and j < n:
            if u[i][0] == v[j][0]:  # Found a match
                graph[u[i][1]].append(v[j][1])
                i += 1
            elif u[i][0] < v[j][0]:
                i += 1
            else:
                j += 1

        # Initialize d array and perform BFS/DFS to find reachable nodes
        d = [0] * n
        visited = [False] * n

        def bfs(start):
            queue = deque([start])
            reachable_values = []
            while queue:
                node = queue.popleft()
                if visited[node]:
                    continue
                visited[node] = True
                reachable_values.append(c[node])
                for neighbor in graph[node]:
                    if not visited[neighbor]:
                        queue.append(neighbor)
            return max(reachable_values, default=0)

        # Compute d[i] for each vertex
        for i in range(n):
            if not visited[i]:
                max_c = bfs(i)
                d[i] = max_c

        count = 0
        # Count valid positions
        for i in range(n):
            if b[i] == n:
                count = max(count, d[i])

        # The answer for this test case
        results.append(count)
    
    return results

# Read input
t = int(input())
test_cases = []

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

# Get results
results = find_max_length(t, test_cases)

# Print results
for res in results:
    print(res)
