Quote:
I tried to use DSU but no success
This is a typical problem from a challenge site, the rule of thumb is that the solutions are never 'there is a standard feature that give the answer', you always have to craft the solution with an ad hoc algorithm.
A first approach is always : solve the problem by hand with short sample data, then solve again with more data until you have a good understanding of the problem. Then you translate you algorithm to code.
The most obvious solution for this problem is the brute force.
For every Q, check the list of integers.
If you want real help, show you work so far and explain its problems.