#include <bits/stdc++.h>

using namespace std;
typedef long long LL;
#define rep(i, l, r) for (int i = l; i<r;i++)
#define print(arr, r, c) rep(i, 0, r) {rep(j, 0, c)cout<<arr[i][j]<<"";cout<<endl;}
#define all(b) b.begin() , b.end()
#define mp(a, b) make_pair(a,b)
#define pb(a) push_back(a)
#define vi vector<int>
#define vd vector<double>
#define vs vector<string>
#define vii vector<pair<int,int>>
#define vvi vector<vector<int>>
#define ii pair<int,int>
#define turnOff(k, i) (k&(~(1<<(i-1))))
#define isOn(k, i) (k&&(1<<i-1)?true:false)
#define pll pair<long long int , long long int>
#define ull unsigned long long int
#define ll  long long int
#define add(a, b) (((a)+(b))%MOD)
#define sub(a, b) (((a)-(b)+MOD)%MOD)
#define mul(a, b) ((1ll*(a)*(b))%MOD)
#ifdef  DEBUG
#define MAXN 5203
#else
#define MAXN 300007
#endif
#define MAXLG 20
#define endl '\n'
#define PI 3.141592653589793238
#define MOD (998244353)
#define INF (2000000000)
#define EPS (0.00000001)
#define treap treapNode

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
#ifdef DEBUG
    freopen("input", "r", stdin);
#endif
    int x,k;
    cin>>x;
    cin>>k;
    int flip[k+1];
    rep (i,0,k)cin>>flip[i];
    int q;
    cin>>q;
    int time[q], mapTime[q];
    ii timeSorted[q];
    ii arr[q];
    int maxTime = 0;

    rep (i,0,q) {
        cin >> time[i];
        cin>>arr[i].first;
        arr[i].second = i;
        timeSorted[i].first = time[i];
        timeSorted[i].second = i;
        maxTime = max(maxTime,time[i]);

    }


    sort(arr,arr+q);
    sort(timeSorted,timeSorted+q);
    rep (i,0,q) {
        mapTime[arr[i].second] = i;
    }
    flip[k] = maxTime+1;
    int bp = 0,up = q-1;
    int sum = 0;
    int dir  =-1;
    int t = 0;
    int ans[q];
    int upPos=  arr[q-1].first;
    int downPos=  arr[0].first;
    for (int timeNow = 0;timeNow<k+1;timeNow++) {

        while(t< q &&  timeSorted[t].first <= flip[timeNow]) {
            int num = mapTime[timeSorted[t].second];
            int diff = (timeSorted[t].first - (timeNow>0?flip[timeNow-1]:0));
            int pos  ;
            int currPos = arr[num].first + sum;
            if (num > up) {
                currPos = upPos;
            } else if (num < bp) {
                currPos = downPos;
            }
            if (dir==1) {
               pos = min(x,currPos+  diff);
            } else {
                pos = max(0,currPos-  diff);
            }
            ans[arr[num].second] = pos;
            t++;

        }
        int diff = (flip[timeNow] - (timeNow>0?flip[timeNow-1]:0));
        if (dir==1) {
            int base = min(x,upPos  +  diff);
            int pos = min(x,arr[up].first + sum +  diff);
            while (up>=0 && base==pos) {
                 up--;
                if (up>=0)
                    pos = min(x,arr[up].first + sum +  diff);
            }
            sum += diff;
            upPos = base;
            downPos = min(x,downPos + diff);
        } else {
            int base = max(0,downPos  - diff);
            int pos = max(0,arr[bp].first + sum -  diff);
            while (bp <q  && base==pos) {
                 bp++;
                if (bp < q )
                    pos = max(0,arr[bp].first + sum -  diff);
            }
            sum -= diff;
            downPos = base;
            upPos = max(0,upPos-diff);
        }

        dir = -dir;
    }

    rep (i,0,q)
        cout<<ans[i]<<" ";
    return 0;
}


Measured memory_bytes: 4352