# Author: Christian Yongwhan Lim
# Date: July 13, 2025

import sys

input = sys.stdin.readline


def main():
    C = int(input())
    for _ in range(C):
        B = int(input())
        h = list(map(int, input().split()))

        left_parent = [-1] * B
        right_parent = [-1] * B
        total_left = [1] * B
        total_right = [1] * B

        st = []
        # Compute right_parent
        for i in range(B):
            while st and h[st[-1]] < h[i]:
                right_parent[st.pop()] = i
            st.append(i)

        st.clear()
        # Compute left_parent
        for i in range(B - 1, -1, -1):
            while st and h[st[-1]] < h[i]:
                left_parent[st.pop()] = i
            st.append(i)

        # Compute total_left counts
        for i in range(B):
            if left_parent[i] != -1:
                total_left[i] = total_left[left_parent[i]] + 1

        # Compute total_right counts
        for i in range(B - 1, -1, -1):
            if right_parent[i] != -1:
                total_right[i] = total_right[right_parent[i]] + 1

        Q = int(input())
        queries = []
        while len(queries) < Q:
            queries.extend(map(int, input().split()))
        for S in queries:
            S -= 1
            print(total_left[S], total_right[S])


if __name__ == "__main__":
    main()

