For each num in the array, I used a dictonary where the values were the indicies. Then basically did a triple for loop optimized with binary search iterating through each of number's lists in the query, however this TLE-ed. Please share if you come up with an optimal solution!