import io import sys from collections import defaultdict, deque, Counter from itertools import permutations, combinations, accumulate from heapq import heappush, heappop from bisect import bisect_right, bisect_left from math import gcd import math _INPUT = """\ 6 5 4 3 7 1 9 2 1 2 3 7 3 5 7 1 10 7 7 7 7 7 3 2 1 1 2 2 1 """ def input(): return sys.stdin.readline()[:-1] def solve(test): N,Q=map(int,input().split()) A=list(map(int,input().split())) B=list(map(int,input().split())) D=[0]*N d=defaultdict(list) for i in range(N): d[A[i]].append(i) tmp=[(0,0)] for i in range(Q): tmp2=[] now=0 for g in d[B[i]]: while now