You can check my code. I did the same. I have commented my code. Hope it solves your doubt.

```
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define ll long long int
#define fio ios_base::sync_with_stdio(false); cin.tie(NULL);
#define br break
#define pb push_back
#define endl "\n"
#define cc continue
#define ee end
using namespace std;
void solve(){
//input
ll n;
cin>>n;
ll i;
vector<ll>v(n);
map<ll,ll>mp;
for(i=0;i<n;i++){
cin>>v[i];
mp[v[i]]++; //Counting the frequency of the elements
}
sort(v.begin(),v.end());
ll ans=-1;
ll q;
cin>>q;
while(q--){
ll a,b;
cin>>a>>b;
ll x=a+b;
//Since, the points are of the form (a,0),(0,a), so the equation of the line
// is x+y=a, so if a point lies on the line, it must satisfy the equation
if(mp[x]){
cout<<"-1"<<endl;
}
//If source lies on destination
else if(a==0 and b==0){
cout<<0<<endl;
}
else{
// If any of the points is greater than the
//greatest element of the vector, it lies
// outside, so the total walls we have to break is n
if(a>v.back() or b>v.back()){
cout<<n<<endl;
}
//We can find the points that we need to pass by
// lower bound, i.e. it gives the index where it is just ;
//greater than the elements, hence the total walls needed to break
else{
ll z=lower_bound(v.begin(),v.end(),x)-v.begin();
cout<<z<<endl;
}
}
}
}
int32_t main()
{
fio;
ll t=1;
cin>>t;
while(t--){
solve();
}
}
```