#include <bits/stdc++.h>
using namespace std;
int main(){
    ios_base::sync_with_stdio(0); cin.tie(0);
    int n; cin >> n;
    int attcnt = 0;
    vector<int> att(n), poi(n);
    for(int i = 0; i < n; ++i)
        {cin >> att[i] >> poi[i]; if(att[i]) attcnt++;}
    int q; cin >> q;
    while(q--){
        int h; cin >> h;
        if(attcnt){
            int sum = 0; int k = 0;
            for(k; k < n; ++k){
                sum += att[k];
                if(sum >= h)
                    break;
            } if(k == n) cout << -1;
            else cout << k + 1<< '\n';
        } else {
            int cur = 0, k = 0;
            for(k; k < n; ++k){
                cur += poi[k];
                h -= cur;
                if(h <= 0)
                    break;
            } if(k == n) cout << -1;
            else cout << k + 1 << '\n';
        }
    }
    return 0;
}