#include<stdio.h>
#define fi first
#define se second
#define M 200000
#include<vector>
#include<algorithm>
using namespace std;
typedef pair<int , int> ii;
int e , s , n , m;
ii petrol[M + 5];
vector<ii> type[5];
ii f[M + 5];
void input(){
    scanf("%d %d %d %d",&e,&s,&n,&m);
    for(int i = 1 ; i <= n ; i++){
        int x , t;
        scanf("%d %d",&petrol[i].se,&petrol[i].fi);
    }
    n++;
    petrol[n] = ii(e , 4);
    sort(petrol + 1 , petrol + 1 + n);
    for(int i = 1 ; i <= n ; i++)   type[petrol[i].se].push_back(ii(petrol[i].fi , i));
    for(int i = 1 ; i <= n ; i++)   if(petrol[i].se == 4){
        n = i;
        break;
    }
}
int goRight(int t,int x){
    if(type[t].size() == 0) return -1;
    if(type[t][0].fi > x)   return -1;
    int id = upper_bound(type[t].begin() , type[t].end() , ii(x , M + 55)) - type[t].begin();
    id--;
    return type[t][id].se;
}
ii cal(int id,int x){
    if(id == n) return ii(0 , 0);
    ii cost = ii(0 , 0);
    for(int i = 3 ; i >= petrol[id].se - 1 ; i--){
        int IDright;
        if(i >= petrol[id].se) IDright = goRight(i , petrol[id].fi + s);
        else IDright = goRight(4 , petrol[id].fi + s);
        if(IDright == -1)   continue;
        if(petrol[IDright].fi <= petrol[id].fi)  continue;
        if(petrol[id].se == 1)  cost.fi += (petrol[IDright].fi - petrol[id].fi - x);
        else if(petrol[id].se == 2) cost.se += (petrol[IDright].fi - petrol[id].fi - x);
        if(f[IDright] != ii(-1 , -1)) return ii(f[IDright].fi + cost.fi , f[IDright].se + cost.se);
        return ii(-1 , - 1);
    }
    if(petrol[id].se == 1) cost.fi += (s - x);
    else if(petrol[id].se == 2) cost.se += (s - x);
    for(int i = petrol[id].se - 1 ; i >= 1 ; i--){
        int IDright = goRight(i , petrol[id].fi + s);
        if(IDright == -1)   continue;
        if(petrol[IDright].fi <= petrol[id].fi)  continue;
        ii val = cal(IDright , s - (petrol[IDright].fi - petrol[id].fi));
        if(val == ii(-1 , -1)) return val;
        return ii(val.fi + cost.fi , val.se + cost.se);
    }
    return ii(-1 , -1);
}
void optimize(){
    f[n] = ii(0 , 0);
    for(int i = n - 1 ; i >= 1 ; i--)   f[i] = cal(i , 0);
}
void query(int x){
    if(x == e){
        printf("%d %d\n",0,0);
        return ;
    }
    int id = -1;
    for(int i = 4 ; i >= 1 ; i--){
        int IDright = goRight(i , x + s);
        if(IDright == -1 || petrol[IDright].fi < x) continue;
        id = IDright;
        break;
    }
    if(id == -1){
        printf("-1 -1\n");
        return ;
    }
    ii res = cal(id , s - (petrol[id].fi - x));
    printf("%d %d\n",res.fi,res.se);
}
main(){
//  freopen("test.inp","r",stdin);
//  freopen("test.out","w",stdout);
    input();
    optimize();
    while(m > 0){
        int u;
        scanf("%d",&u);
        query(u);
        m--;
    }
}


#include<stdio.h>
#define fi first
#define se second
#define M 100000
#include<vector>
#include<algorithm>
using namespace std;
typedef pair<int , int> ii;
int e , s , n , m;
ii petrol[M + 5];
vector<ii> type[5];
ii f[M + 5];
void input(){
    scanf("%d %d %d %d",&e,&s,&n,&m);
    for(int i = 1 ; i <= n ; i++){
        int x , t;
        scanf("%d %d",&petrol[i].se,&petrol[i].fi);
    }
    n++;
    petrol[n] = ii(e , 4);
    sort(petrol + 1 , petrol + 1 + n);
    for(int i = 1 ; i <= n ; i++)   type[petrol[i].se].push_back(ii(petrol[i].fi , i));
    for(int i = 1 ; i <= n ; i++)   if(petrol[i].se == 4){
        n = i;
        break;
    }
}
int goRight(int t,int x){
    if(type[t].size() == 0) return -1;
    if(type[t][0].fi > x)   return -1;
    int id = upper_bound(type[t].begin() , type[t].end() , ii(x , M + 55)) - type[t].begin();
    id--;
    return type[t][id].se;
}
ii cal(int id,int x){
//	printf("%d %d\n",id,x);
    ii cost = ii(0 , 0);
    for(int i = 3 ; i >= petrol[id].se - 1 ; i--){
    	int IDright;
        if(i >= petrol[id].se) IDright = goRight(i , petrol[id].fi + s);
        else IDright = goRight(4 , petrol[id].fi + s);
		if(IDright == -1)   continue;
        if(petrol[IDright].fi <= petrol[id].fi)  continue;
        if(petrol[id].se == 1)  cost.fi += (petrol[IDright].fi - petrol[id].fi - x);
        else if(petrol[id].se == 2) cost.se += (petrol[IDright].fi - petrol[id].fi - x);
        if(f[IDright] != ii(-1 , -1)) return ii(f[IDright].fi + cost.fi , f[IDright].se + cost.se);
        return ii(-1 , - 1);
    }
    if(petrol[id].se == 1) cost.fi += (s - x);
    else if(petrol[id].se == 2) cost.se += (s - x);
    for(int i = petrol[id].se - 1 ; i >= 1 ; i--){
        int IDright = goRight(i , petrol[id].fi + s);
        if(IDright == -1)   continue;
        if(petrol[IDright].fi <= petrol[id].fi)  continue;
        ii val = cal(IDright , s - (petrol[IDright].fi - petrol[id].fi));
        if(val == ii(-1 , -1)) return val;
        return ii(val.fi + cost.fi , val.se + cost.se);
    }
    return ii(-1 , -1);
}
void optimize(){
	f[n] = ii(0 , 0);
	for(int i = n - 1 ; i >= 1 ; i--)	f[i] = cal(i , 0);
}
void query(int x){
	if(x == e){
		printf("%d %d\n",0,0);
		return ;
	}
	int id = -1;
	for(int i = 4 ; i >= 1 ; i--){
		int IDright = goRight(i , x + s);
        if(IDright == -1 || petrol[IDright].fi <= x)	continue;
        id = IDright;
        break;
	}
	if(id == -1){
		printf("-1 -1\n");
		return ;
	}
	ii res = cal(id , s - (petrol[id].fi - x));
	printf("%d %d\n",res.fi,res.se);
}
main(){
//	freopen("test.inp","r",stdin);
//	freopen("test.out","w",stdout);
	input();
	optimize();
	while(m > 0){
		int u;
		scanf("%d",&u);
		query(u);
		m--;
	}
}


#include<stdio.h>
#define fi first
#define se second
#define M 100000
#include<vector>
#include<algorithm>
using namespace std;
typedef pair<int , int> ii;
int e , s , n , m;
ii petrol[M + 5];
vector<ii> type[5];
ii f[M + 5];
void input(){
    scanf("%d %d %d %d",&e,&s,&n,&m);
    for(int i = 1 ; i <= n ; i++){
        int x , t;
        scanf("%d %d",&petrol[i].se,&petrol[i].fi);
    }
    n++;
    petrol[n] = ii(e , 4);
    sort(petrol + 1 , petrol + 1 + n);
    for(int i = 1 ; i <= n ; i++)   type[petrol[i].se].push_back(ii(petrol[i].fi , i));
    for(int i = 1 ; i <= n ; i++)   if(petrol[i].se == 4){
        n = i;
        break;
    }
}
int goRight(int t,int x){
    if(type[t].size() == 0) return -1;
    if(type[t][0].fi > x)   return -1;
    int id = upper_bound(type[t].begin() , type[t].end() , ii(x , M + 55)) - type[t].begin();
    id--;
    return type[t][id].se;
}
ii cal(int id,int x){
//	printf("%d %d\n",id,x);
    ii cost = ii(0 , 0);
    for(int i = 3 ; i >= petrol[id].se - 1 ; i--){
    	int IDright;
        if(i >= petrol[id].se) IDright = goRight(i , petrol[id].fi + s);
        else IDright = goRight(4 , petrol[id].fi + s);
		if(IDright == -1)   continue;
        if(petrol[IDright].fi <= petrol[id].fi)  continue;
        if(petrol[id].se == 1)  cost.fi += (petrol[IDright].fi - petrol[id].fi - x);
        else if(petrol[id].se == 2) cost.se += (petrol[IDright].fi - petrol[id].fi - x);
        if(f[IDright] != ii(-1 , -1)) return ii(f[IDright].fi + cost.fi , f[IDright].se + cost.se);
        return ii(-1 , - 1);
    }
    if(petrol[id].se == 1) cost.fi += (s - x);
    else if(petrol[id].se == 2) cost.se += (s - x);
    for(int i = petrol[id].se - 1 ; i >= 1 ; i--){
        int IDright = goRight(i , petrol[id].fi + s);
        if(IDright == -1)   continue;
        if(petrol[IDright].fi <= petrol[id].fi)  continue;
        ii val = cal(IDright , s - (petrol[IDright].fi - petrol[id].fi));
        if(val == ii(-1 , -1)) return val;
        return ii(val.fi + cost.fi , val.se + cost.se);
    }
    return ii(-1 , -1);
}
void optimize(){
	f[n] = ii(0 , 0);
	for(int i = n - 1 ; i >= 1 ; i--)	f[i] = cal(i , 0);
}
void query(int x){
	int id = lower_bound(petrol + 1 , petrol + 1 + n , ii(x , 0)) - (petrol);
	if(s - (petrol[id].fi - x) < 0)	{
		printf("%d %d\n",-1,-1);
		return ;
	}
	ii res = cal(id , s - (petrol[id].fi - x));
	printf("%d %d\n",res.fi,res.se);
}
main(){
//	freopen("test.inp","r",stdin);
	input();
	optimize();
	while(m > 0){
		int u;
		scanf("%d",&u);
		query(u);
		m--;
	}
}


#include<stdio.h>
#define fi first
#define se second
#define M 100000
#include<vector>
#include<algorithm>
using namespace std;
typedef pair<int , int> ii;
int e , s , n , m;
ii petrol[M + 5];
vector<ii> type[5];
ii f[M + 5];
void input(){
    scanf("%d %d %d %d",&e,&s,&n,&m);
    for(int i = 1 ; i <= n ; i++){
        int x , t;
        scanf("%d %d",&petrol[i].se,&petrol[i].fi);
    }
    n++;
    petrol[n] = ii(e , 4);
    sort(petrol + 1 , petrol + 1 + n);
    for(int i = 1 ; i <= n ; i++)   type[petrol[i].se].push_back(ii(petrol[i].fi , i));
    for(int i = 1 ; i <= n ; i++)   if(petrol[i].se == 4){
        n = i;
        break;
    }
}
int goRight(int t,int x){
    if(type[t].size() == 0) return -1;
    if(type[t][0].fi > x)   return -1;
    int id = upper_bound(type[t].begin() , type[t].end() , ii(x , M + 55)) - type[t].begin();
    id--;
    return type[t][id].se;
}
ii cal(int id,int x){
//	printf("%d %d\n",id,x);
    ii cost = ii(0 , 0);
    for(int i = 3 ; i >= petrol[id].se - 1 ; i--){
    	int IDright;
        if(i >= petrol[id].se) IDright = goRight(i , petrol[id].fi + s);
        else IDright = goRight(4 , petrol[id].fi + s);
		if(IDright == -1)   continue;
        if(petrol[IDright].fi <= petrol[id].fi)  continue;
        if(petrol[id].se == 1)  cost.fi += (petrol[IDright].fi - petrol[id].fi - x);
        else if(petrol[id].se == 2) cost.se += (petrol[IDright].fi - petrol[id].fi - x);
        if(f[IDright] != ii(-1 , -1)) return ii(f[IDright].fi + cost.fi , f[IDright].se + cost.se);
        return ii(-1 , - 1);
    }
    if(petrol[id].se == 1) cost.fi += (s - x);
    else if(petrol[id].se == 2) cost.se += (s - x);
    for(int i = petrol[id].se - 1 ; i >= 1 ; i--){
        int IDright = goRight(i , petrol[id].fi + s);
        if(IDright == -1)   continue;
        if(petrol[IDright].fi <= petrol[id].fi)  continue;
        ii val = cal(IDright , s - (petrol[IDright].fi - petrol[id].fi));
        if(val == ii(-1 , -1)) return val;
        return ii(val.fi + cost.fi , val.se + cost.se);
    }
    return ii(-1 , -1);
}
void optimize(){
	f[n] = ii(0 , 0);
	for(int i = n - 1 ; i >= 1 ; i--)	f[i] = cal(i , 0);
}
void query(int x){
	int id = -1;
	for(int i = 4 ; i >= 1 ; i--){
		int IDright = goRight(i , x + s);
        if(IDright == -1 || petrol[IDright].fi <= x)	continue;
        id = IDright;
        break;
	}
	if(id == -1){
		printf("-1 -1\n");
		return ;
	}
	ii res = cal(id , s - (petrol[id].fi - x));
	printf("%d %d\n",res.fi,res.se);
}
main(){
//	freopen("test.inp","r",stdin);
//	freopen("test.out","w",stdout);
	input();
	optimize();
	while(m > 0){
		int u;
		scanf("%d",&u);
		query(u);
		m--;
	}
}


#include <algorithm>
#include <vector>
#include <iostream>

using namespace std;

const int maxn = 2e5 + 1;

vector<int> st[3];
int dp[3][maxn], ans[3], e, s, n, m;

int solve(int x, int type)
{
	int t = lower_bound(st[type].begin(), st[type].end(), x) - st[type].begin();
	// cout << dp[type][t] + max(0, st[type][t] - x - s) << endl;
	return dp[type][t] + max(0, st[type][t] - x - s);
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cin >> e >> s >> n >> m;
	for (int i = 0; i < 3; i++)
		st[i].push_back(e);
	int type, x;
	for (int i = 0; i < n; i++)
	{
		cin >> type >> x;
		if (x > e)
			continue;
		for (int j = 0; j < type; j++)
			st[j].push_back(x);
	}
	for (int i = 0; i < 3; i++)
	{
		sort(st[i].begin(), st[i].end());
		for (int j = st[i].size() - 2; j > -1; j--)
			dp[i][j] = dp[i][j + 1] + max(0, st[i][j + 1] - st[i][j] - s);
	}
	for (int i = 0; i < m; i++)
	{
		cin >> x;
		for (int j = 0; j < 3; j++)
			ans[j] = solve(x, j);
		if (ans[0])
			cout << -1 << ' ' << -1 << endl;
		else
			cout << ans[1] << ' ' << ans[2] - ans[1] << endl;
	}
}


#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <list>
#include <stack>
#include <deque>
#include <queue>
#include <algorithm>
#include <cassert>
#include <cmath>
#include <ctime>
#include <sstream>
#include <unordered_set>
#include <unordered_map>
#include <functional>
#include <bitset>
#include <valarray>
#include <utility>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;

#ifdef LOCAL_RUN
#define debug(x) cerr << #x << ": "  << (x) << "\n";
#else
#define debug(x) ;
#endif

#define all(v) (v).begin(), (v).end()
#define MP make_pair

template<class T>
class IsIterable__ {static void f(...); template<class U> static typename U::const_iterator f(const U&);
public:const static bool value = !std::is_same<void, decltype(f(std::declval<T>()))>::value;};

template <class F, class S> ostream& operator << (ostream& o, const pair<F,S>& p) {
return o << "(" << p.first << ", " << p.second << ")";}

template<class C>void O__(ostream& o, const C& c) {
bool f = 1; for(const auto& x: c) {if (!f) o << ", "; if (IsIterable__<decltype(x)>::value) o << "\n"; f = 0; o << x;}}

template <class T>
ostream& operator << (ostream& o, const vector<T>& v) {o << "[";O__(o, v);o << "]";return o;}

template <class T, class V>
ostream& operator << (ostream& o, const map<T, V>& v) {o << "{";O__(o, v);o << "}"; return o;}

template <class T>
ostream& operator << (ostream& o, const set<T>& v) {o << "{";O__(o, v);o << "}";return o;}

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<double, double> pdd;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<vii> viii;

const double PI = 3.1415926535897932384626433832795;
const double EPS = 1e-9;
const int INF = std::numeric_limits<int>::max();
const long long LLINF = std::numeric_limits<ll>::max();

#if GCC_VERSION > 40900
// supports find_by_order(int) and order_of_key(Key)
template<class Key, class Value>
using MapWithOrderStatistics = tree<Key, Value,
      std::less<Key>, rb_tree_tag /*splay_tree_tag*/,
      tree_order_statistics_node_update>;
#endif

template<class V>
void r(V& v) {
    for (auto& x: v) {
        cin >> x;
    }
}

void solve(vector<pii>& ans, int start, int vol, const vi& type, const vi& pos, vector<pii> fi) {
    sort(all(fi));
    for (int tt = 1; tt <= 3; ++tt) {
        //debug(tt);
        vector<pii> segs;
        segs.emplace_back(start, +1);
        segs.emplace_back(start + vol, -1);
        for (size_t i = 0; i < pos.size(); ++i) {
            if (type[i] >= tt && pos[i] >= start) {
                segs.emplace_back(pos[i], +1);
                segs.emplace_back(pos[i] + vol, -1);
            }
        }
        sort(all(segs));
        //debug(segs);
        int bal = 0;
        size_t j = 0;
        vi gaps(ans.size());
        for (size_t i = 0; i < fi.size(); ++i) {
            int x = fi[i].first;
            int ind = fi[i].second;
            if (i) {
                gaps[ind] = gaps[fi[i-1].second];
            }
            while(j < segs.size() && segs[j].first <= x) {
                if (bal == 0 && j > 0) {
                    gaps[ind] += segs[j].first - segs[j - 1].first;
                }
                bal += segs[j].second;
                ++j;
            }
            if (bal == 0) {
                --j;
                if (i == 0 || segs[j].first >= fi[i-1].first) {
                    gaps[ind] += x - segs[j].first;
                } else {
                    gaps[ind] += x - fi[i-1].first;
                }
                ++j;
            }
        }
        for (size_t i = 0; i < fi.size(); ++i) {
            int ind = fi[i].second;
            if (tt == 1) {
                if (gaps[ind] > 0) {
                    ans[ind] = pii(-1,-1);
                }
            }
            if (tt == 2) {
                if (ans[ind] != pii(-1,-1)){
                    ans[ind].first = gaps[ind];
                }
            }
            if (tt == 3) {
                if (ans[ind] != pii(-1,-1)){
                    ans[ind].second = gaps[ind] - ans[ind].first;
                }
            }
        }
    }
}

int main() {
    std::ios_base::sync_with_stdio(false);
    int e,s,n,m;
    cin >> e >> s >> n >> m;
    vi t(n); ;
    vi x(n);
    for (int i = 0; i < n; ++i) {
        cin >> t[i] >> x[i];
    }
    vi f(m); r(f);

    vector<pii> ans(m, pii(-2,-2));
    vector<pii> fi;
    for (int i = 0; i < m; ++i) {
        if (f[i] > e) {
            fi.emplace_back(f[i], i);
        }
    }
    solve(ans, e, s, t, x, fi);

    fi.clear();
    for (int i = 0; i < m; ++i) {
        if (f[i] == e) {
            ans[i] = pii(0,0);
        }
        if (f[i] < e) {
            fi.emplace_back(-f[i], i);
        }
    }
    for (int& a: x) {
        a*=-1;
    }
    solve(ans, -e, s, t, x, fi);
    for (auto a: ans) {
        cout << a.first << " " << a.second << "\n";
    }

    return 0;
}


#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <list>
#include <stack>
#include <deque>
#include <queue>
#include <algorithm>
#include <cassert>
#include <cmath>
#include <ctime>
#include <sstream>
#include <unordered_set>
#include <unordered_map>
#include <functional>
#include <bitset>
#include <valarray>
#include <utility>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;

#ifdef LOCAL_RUN
#define debug(x) cerr << #x << ": "  << (x) << "\n";
#else
#define debug(x) ;
#endif

#define all(v) (v).begin(), (v).end()
#define MP make_pair

template<class T>
class IsIterable__ {static void f(...); template<class U> static typename U::const_iterator f(const U&);
public:const static bool value = !std::is_same<void, decltype(f(std::declval<T>()))>::value;};

template <class F, class S> ostream& operator << (ostream& o, const pair<F,S>& p) {
return o << "(" << p.first << ", " << p.second << ")";}

template<class C>void O__(ostream& o, const C& c) {
bool f = 1; for(const auto& x: c) {if (!f) o << ", "; if (IsIterable__<decltype(x)>::value) o << "\n"; f = 0; o << x;}}

template <class T>
ostream& operator << (ostream& o, const vector<T>& v) {o << "[";O__(o, v);o << "]";return o;}

template <class T, class V>
ostream& operator << (ostream& o, const map<T, V>& v) {o << "{";O__(o, v);o << "}"; return o;}

template <class T>
ostream& operator << (ostream& o, const set<T>& v) {o << "{";O__(o, v);o << "}";return o;}

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<double, double> pdd;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<vii> viii;

const double PI = 3.1415926535897932384626433832795;
const double EPS = 1e-9;
const int INF = std::numeric_limits<int>::max();
const long long LLINF = std::numeric_limits<ll>::max();

#if GCC_VERSION > 40900
// supports find_by_order(int) and order_of_key(Key)
template<class Key, class Value>
using MapWithOrderStatistics = tree<Key, Value,
      std::less<Key>, rb_tree_tag /*splay_tree_tag*/,
      tree_order_statistics_node_update>;
#endif

template<class V>
void r(V& v) {
    for (auto& x: v) {
        cin >> x;
    }
}

void solve(vector<pii>& ans, int start, int vol, const vi& type, const vi& pos, vector<pii> fi) {
    sort(all(fi));
    for (int tt = 1; tt <= 3; ++tt) {
        //debug(tt);
        vector<pii> segs;
        segs.emplace_back(start, +1);
        segs.emplace_back(start + vol, -1);
        for (size_t i = 0; i < pos.size(); ++i) {
            if (type[i] >= tt && pos[i] >= start) {
                segs.emplace_back(pos[i], +1);
                segs.emplace_back(pos[i] + vol, -1);
            }
        }
        sort(all(segs));
        //debug(segs);
        int bal = 0;
        size_t j = 0;
        vi gaps(ans.size());
        int add = 0;
        for (size_t i = 0; i < fi.size(); ++i) {
            int x = fi[i].first;
            int ind = fi[i].second;
            if (i) {
                gaps[ind] = gaps[fi[i-1].second] - add;
            }
            while(j < segs.size() && segs[j].first <= x) {
                if (bal == 0 && j > 0) {
                    gaps[ind] += segs[j].first - segs[j - 1].first;
                }
                bal += segs[j].second;
                ++j;
            }
            if (bal == 0) {
                --j;
                add =  x - segs[j].first;
                gaps[ind] += add;
                ++j;
            } else {
                add = 0;
            }
        }
        debug(gaps);
        for (size_t i = 0; i < fi.size(); ++i) {
            int ind = fi[i].second;
            if (tt == 1) {
                if (gaps[ind] > 0) {
                    ans[ind] = pii(-1,-1);
                }
            }
            if (tt == 2) {
                if (ans[ind] != pii(-1,-1)){
                    ans[ind].first = gaps[ind];
                }
            }
            if (tt == 3) {
                if (ans[ind] != pii(-1,-1)){
                    ans[ind].second = gaps[ind] - ans[ind].first;
                }
            }
        }
    }
}

int main() {
    std::ios_base::sync_with_stdio(false);
    int e,s,n,m;
    cin >> e >> s >> n >> m;
    vi t(n); ;
    vi x(n);
    for (int i = 0; i < n; ++i) {
        cin >> t[i] >> x[i];
    }
    vi f(m); r(f);

    vector<pii> ans(m, pii(-2,-2));
    vector<pii> fi;
    for (int i = 0; i < m; ++i) {
        if (f[i] > e) {
            fi.emplace_back(f[i], i);
        }
    }
    solve(ans, e, s, t, x, fi);

    fi.clear();
    for (int i = 0; i < m; ++i) {
        if (f[i] == e) {
            ans[i] = pii(0,0);
        }
        if (f[i] < e) {
            fi.emplace_back(-f[i], i);
        }
    }
    for (int& a: x) {
        a*=-1;
    }
    solve(ans, -e, s, t, x, fi);
    for (auto a: ans) {
        cout << a.first << " " << a.second << "\n";
    }

    return 0;
}


#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <list>
#include <stack>
#include <deque>
#include <queue>
#include <algorithm>
#include <cassert>
#include <cmath>
#include <ctime>
#include <sstream>
#include <unordered_set>
#include <unordered_map>
#include <functional>
#include <bitset>
#include <valarray>
#include <utility>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;

#ifdef LOCAL_RUN
#define debug(x) cerr << #x << ": "  << (x) << "\n";
#else
#define debug(x) ;
#endif

#define all(v) (v).begin(), (v).end()
#define MP make_pair

template<class T>
class IsIterable__ {static void f(...); template<class U> static typename U::const_iterator f(const U&);
public:const static bool value = !std::is_same<void, decltype(f(std::declval<T>()))>::value;};

template <class F, class S> ostream& operator << (ostream& o, const pair<F,S>& p) {
return o << "(" << p.first << ", " << p.second << ")";}

template<class C>void O__(ostream& o, const C& c) {
bool f = 1; for(const auto& x: c) {if (!f) o << ", "; if (IsIterable__<decltype(x)>::value) o << "\n"; f = 0; o << x;}}

template <class T>
ostream& operator << (ostream& o, const vector<T>& v) {o << "[";O__(o, v);o << "]";return o;}

template <class T, class V>
ostream& operator << (ostream& o, const map<T, V>& v) {o << "{";O__(o, v);o << "}"; return o;}

template <class T>
ostream& operator << (ostream& o, const set<T>& v) {o << "{";O__(o, v);o << "}";return o;}

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<double, double> pdd;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<vii> viii;

const double PI = 3.1415926535897932384626433832795;
const double EPS = 1e-9;
const int INF = std::numeric_limits<int>::max();
const long long LLINF = std::numeric_limits<ll>::max();

#if GCC_VERSION > 40900
// supports find_by_order(int) and order_of_key(Key)
template<class Key, class Value>
using MapWithOrderStatistics = tree<Key, Value,
      std::less<Key>, rb_tree_tag /*splay_tree_tag*/,
      tree_order_statistics_node_update>;
#endif

template<class V>
void r(V& v) {
    for (auto& x: v) {
        cin >> x;
    }
}

void solve(vector<pii>& ans, int start, int vol, const vi& type, const vi& pos, vector<pii> fi) {
    sort(all(fi));
    for (int tt = 1; tt <= 3; ++tt) {
        //debug(tt);
        vector<pii> segs;
        segs.emplace_back(start, +1);
        segs.emplace_back(start + vol, -1);
        for (size_t i = 0; i < pos.size(); ++i) {
            if (type[i] >= tt && pos[i] >= start) {
                segs.emplace_back(pos[i], +1);
                segs.emplace_back(pos[i] + vol, -1);
            }
        }
        sort(all(segs));
        //debug(segs);
        int bal = 0;
        size_t j = 0;
        vi gaps(ans.size());
        for (size_t i = 0; i < fi.size(); ++i) {
            int x = fi[i].first;
            int ind = fi[i].second;
            if (i) {
                gaps[ind] = gaps[fi[i-1].second];
            }
            while(j < segs.size() && segs[j].first <= x) {
                if (bal == 0 && j > 0) {
                    gaps[ind] += segs[j].first - segs[j - 1].first;
                }
                bal += segs[j].second;
                ++j;
            }
            //debug(x);
            //debug(gaps[ind]);
            if (j == segs.size()) {
                if (i==0 || segs.back().first >= fi[i-1].first) {
                    gaps[ind] += x - segs.back().first;
                } else {
                    gaps[ind] += x - fi[i-1].first;
                }
            }
            //debug(gaps[ind]);
        }
        for (size_t i = 0; i < fi.size(); ++i) {
            int ind = fi[i].second;
            if (tt == 1) {
                if (gaps[ind] > 0) {
                    ans[ind] = pii(-1,-1);
                }
            }
            if (tt == 2) {
                if (ans[ind] != pii(-1,-1)){
                    ans[ind].first = gaps[ind];
                }
            }
            if (tt == 3) {
                if (ans[ind] != pii(-1,-1)){
                    ans[ind].second = gaps[ind] - ans[ind].first;
                }
            }
        }
    }
}

int main() {
    std::ios_base::sync_with_stdio(false);
    int e,s,n,m;
    cin >> e >> s >> n >> m;
    vi t(n); ;
    vi x(n);
    for (int i = 0; i < n; ++i) {
        cin >> t[i] >> x[i];
    }
    vi f(m); r(f);

    vector<pii> ans(m, pii(-2,-2));
    vector<pii> fi;
    for (int i = 0; i < m; ++i) {
        if (f[i] > e) {
            fi.emplace_back(f[i], i);
        }
    }
    solve(ans, e, s, t, x, fi);

    debug(ans);
    fi.clear();
    for (int i = 0; i < m; ++i) {
        if (f[i] == e) {
            ans[i] = pii(0,0);
        }
        if (f[i] < e) {
            fi.emplace_back(-f[i], i);
        }
    }
    for (int& a: x) {
        a*=-1;
    }
    solve(ans, -e, s, t, x, fi);
    for (auto a: ans) {
        cout << a.first << " " << a.second << "\n";
    }

    return 0;
}


#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <list>
#include <stack>
#include <deque>
#include <queue>
#include <algorithm>
#include <cassert>
#include <cmath>
#include <ctime>
#include <sstream>
#include <unordered_set>
#include <unordered_map>
#include <functional>
#include <bitset>
#include <valarray>
#include <utility>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;

#ifdef LOCAL_RUN
#define debug(x) cerr << #x << ": "  << (x) << "\n";
#else
#define debug(x) ;
#endif

#define all(v) (v).begin(), (v).end()
#define MP make_pair

template<class T>
class IsIterable__ {static void f(...); template<class U> static typename U::const_iterator f(const U&);
public:const static bool value = !std::is_same<void, decltype(f(std::declval<T>()))>::value;};

template <class F, class S> ostream& operator << (ostream& o, const pair<F,S>& p) {
return o << "(" << p.first << ", " << p.second << ")";}

template<class C>void O__(ostream& o, const C& c) {
bool f = 1; for(const auto& x: c) {if (!f) o << ", "; if (IsIterable__<decltype(x)>::value) o << "\n"; f = 0; o << x;}}

template <class T>
ostream& operator << (ostream& o, const vector<T>& v) {o << "[";O__(o, v);o << "]";return o;}

template <class T, class V>
ostream& operator << (ostream& o, const map<T, V>& v) {o << "{";O__(o, v);o << "}"; return o;}

template <class T>
ostream& operator << (ostream& o, const set<T>& v) {o << "{";O__(o, v);o << "}";return o;}

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<double, double> pdd;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<vii> viii;

const double PI = 3.1415926535897932384626433832795;
const double EPS = 1e-9;
const int INF = std::numeric_limits<int>::max();
const long long LLINF = std::numeric_limits<ll>::max();

#if GCC_VERSION > 40900
// supports find_by_order(int) and order_of_key(Key)
template<class Key, class Value>
using MapWithOrderStatistics = tree<Key, Value,
      std::less<Key>, rb_tree_tag /*splay_tree_tag*/,
      tree_order_statistics_node_update>;
#endif

template<class V>
void r(V& v) {
    for (auto& x: v) {
        cin >> x;
    }
}

void solve(vector<pii>& ans, int start, int vol, const vi& type, const vi& pos, vector<pii> fi) {
    sort(all(fi));
    for (int tt = 1; tt <= 3; ++tt) {
        //debug(tt);
        vector<pii> segs;
        segs.emplace_back(start, +1);
        segs.emplace_back(start + vol, -1);
        for (size_t i = 0; i < pos.size(); ++i) {
            if (type[i] >= tt && pos[i] >= start) {
                segs.emplace_back(pos[i], +1);
                segs.emplace_back(pos[i] + vol, -1);
            }
        }
        sort(all(segs));
        //debug(segs);
        int bal = 0;
        size_t j = 0;
        vi gaps(ans.size());
        int add = 0;
        for (size_t i = 0; i < fi.size(); ++i) {
            int x = fi[i].first;
            int ind = fi[i].second;
            if (i) {
                gaps[ind] = gaps[fi[i-1].second] - add;
            }
            while(j < segs.size() && segs[j].first <= x) {
                if (bal == 0 && j > 0) {
                    gaps[ind] += segs[j].first - segs[j - 1].first;
                }
                bal += segs[j].second;
                ++j;
            }
            if (bal == 0) {
                --j;
                add =  x - segs[j].first;
                gaps[ind] += add;
                ++j;
            }
        }
        for (size_t i = 0; i < fi.size(); ++i) {
            int ind = fi[i].second;
            if (tt == 1) {
                if (gaps[ind] > 0) {
                    ans[ind] = pii(-1,-1);
                }
            }
            if (tt == 2) {
                if (ans[ind] != pii(-1,-1)){
                    ans[ind].first = gaps[ind];
                }
            }
            if (tt == 3) {
                if (ans[ind] != pii(-1,-1)){
                    ans[ind].second = gaps[ind] - ans[ind].first;
                }
            }
        }
    }
}

int main() {
    std::ios_base::sync_with_stdio(false);
    int e,s,n,m;
    cin >> e >> s >> n >> m;
    vi t(n); ;
    vi x(n);
    for (int i = 0; i < n; ++i) {
        cin >> t[i] >> x[i];
    }
    vi f(m); r(f);

    vector<pii> ans(m, pii(-2,-2));
    vector<pii> fi;
    for (int i = 0; i < m; ++i) {
        if (f[i] > e) {
            fi.emplace_back(f[i], i);
        }
    }
    solve(ans, e, s, t, x, fi);

    fi.clear();
    for (int i = 0; i < m; ++i) {
        if (f[i] == e) {
            ans[i] = pii(0,0);
        }
        if (f[i] < e) {
            fi.emplace_back(-f[i], i);
        }
    }
    for (int& a: x) {
        a*=-1;
    }
    solve(ans, -e, s, t, x, fi);
    for (auto a: ans) {
        cout << a.first << " " << a.second << "\n";
    }

    return 0;
}


#include <iostream>
#include <algorithm>
#include <cstdio>
#include <string.h>
#include <vector>
using namespace std;
typedef long long LL;
const int maxn=200005;
const int INF=2147483647;
struct point{
  int x,t;
  point(int cx=0, int ct=0){
     x=cx; t=ct;
  }
  bool operator <(const point &rhs)const{
     return x<rhs.x;
  }
}P[maxn];
int D[4][maxn],num[4];
int dp[maxn][3];
int e,s,n,m;
int bitlook1(int x,int *C, int n)
{
     int L=0,R=n-1,ans=-1;
     while(L<=R)
        {
             int mid=(L+R)>>1;
             int id=C[mid];
             if( P[id].x>=x  ){
                ans=mid;
                R=mid-1;
             }else{
                L=mid+1;
             }
        }
        return ans;
}
void cmp(int &A, int &B,int &V, int C, int D, int DV)
{
      if(A>=C){
         if(A==C){
            if(B<D) return ;
            if(B>D){
                B=D;
                V=DV;
            }else{
               V=min(V,DV);
            }
         }
         else {
            A=C; B=D;
            V=DV;
         }
      }
}
void solve1(int id)
{
     int loc=P[id].x;
     int d1=bitlook1(loc+1,D[1],num[1]);
     int d2=bitlook1(loc+1,D[2],num[2]);
     int d3=bitlook1(loc+1,D[3],num[3]);
     if(d3!=-1)d3=D[3][d3];
     if(d2!=-1)d2=D[2][d2];
     if(d1!=-1)d1=D[1][d1];
     if( d3!=-1 && P[d3].x <= loc+s )
     {
          int cp1 = dp[d3][1]+P[d3].x-loc;
          int cp2 = dp[d3][2];
          cmp(dp[id][1],dp[id][2],dp[id][0],cp1,cp2,P[d3].x-loc);
     }
     if(d2!=-1 && P[d2].x<=loc+s)
     {
          int cp1 = dp[d2][1]+P[d2].x-loc;
          int cp2 = dp[d2][2];
          cmp(dp[id][1],dp[id][2],dp[id][0],cp1,cp2,P[d2].x-loc);
     }
    if( d1!=-1 && P[d1].x<=loc+s)
     {
         int cp1 = dp[d1][1]+P[d1].x-loc;
         int cp2 = dp[d1][2];
          cmp(dp[id][1],dp[id][2],dp[id][0],cp1,cp2,P[d1].x-loc);
     }
}
int bitlook2(int x,int *C, int n)
{
     int L=0,R=n-1,ans=-1;
     while(L<=R)
        {
             int mid=(L+R)>>1;
             int id=C[mid];
             if( P[id].x<=x  ){
                ans=mid;
                L=mid+1;
             }else{
                R=mid-1;
             }
        }
        return ans;
}
void solve2(int id)
{
     int loc=P[id].x;
     int d1=bitlook2(loc+s,D[1],num[1]);
     int d2=bitlook1(loc+1,D[2],num[2]);
     int d3=bitlook1(loc+1,D[3],num[3]);
     if(d3!=-1)d3=D[3][d3];
     if(d2!=-1)d2=D[2][d2];
     if(d1!=-1)d1=D[1][d1];
     if( d3!=-1 && P[d3].x <= loc+s )
     {
          int cp1 = dp[d3][1];
          int cp2 = dp[d3][2]+P[d3].x-loc;
          cmp(dp[id][1],dp[id][2],dp[id][0],cp1,cp2,P[d3].x-loc);
     }
     if(d2!=-1 && P[d2].x<=loc+s)
     {
          int cp1 = dp[d2][1];
          int cp2 = dp[d2][2]+P[d2].x-loc;
          cmp(dp[id][1],dp[id][2],dp[id][0],cp1,cp2,P[d3].x-loc);
     }

    if( d1!=-1&&P[d1].x>loc)
     {
         int cp0=s;
         int lit = s-(P[d1].x-loc);
         int cp1 = dp[d1][1]-min(lit,dp[d1][0]);
         int cp2 = dp[d1][2]+cp0;
          cmp(dp[id][1],dp[id][2],dp[id][0],cp1,cp2,cp0);
     }
}
void solve3(int id)
{
     int loc=P[id].x;
     int d1=bitlook2(loc+s,D[1],num[1]);
     int d2=bitlook2(loc+s,D[2],num[2]);
     int d3=bitlook1(loc+1,D[3],num[3]);
      if(d3!=-1)d3=D[3][d3];
     if(d2!=-1)d2=D[2][d2];
     if(d1!=-1)d1=D[1][d1];

     if( d3!=-1 && P[d3].x<=loc+s )
     {
         cmp(dp[id][1],dp[id][2],dp[id][0],dp[d3][1],dp[d3][2],0);
     }
     if(d2!=-1&&P[d2].x>loc)
     {
         int lit = s-(P[d2].x-loc);
         int cp1 = dp[d2][1];
         int cp2 = dp[d2][2]-min(dp[d2][0],lit);
         cmp(dp[id][1],dp[id][2],dp[id][0],cp1,cp2,0);
     }
     if(d1!=-1&&P[d1].x>loc)
     {
         int lit = s-(P[d1].x-loc);
         int cp1 = dp[d1][1]-min(dp[d1][0],lit);
         int cp2 = dp[d1][2];
         cmp(dp[id][1],dp[id][2],dp[id][0],cp1,cp2,0);
     }
}
void solve4(int loc, int &S1,int &S2)
{
     int k;
     int d1=bitlook2(loc+s,D[1],num[1]);
     int d2=bitlook2(loc+s,D[2],num[2]);
     int d3=bitlook1(loc+1,D[3],num[3]);
     if(d3!=-1)d3=D[3][d3];
     if(d2!=-1)d2=D[2][d2];
     if(d1!=-1)d1=D[1][d1];
     if( d3!=-1 && P[d3].x<=loc+s &&dp[d3][1]!=INF)
     {
         cmp(S1,S2,k,dp[d3][1],dp[d3][2],0);
     }
     if(d2!=-1&&P[d2].x>loc&&dp[d2][1]!=INF)
     {
         int lit = s-(P[d2].x-loc);
         int cp1 = dp[d2][1];
         int cp2 = dp[d2][2]-min(dp[d2][0],lit);
         cmp(S1,S2,k,cp1,cp2,0);
     }
     if(d1!=-1&&P[d1].x>loc&&dp[d1][1]!=INF)
     {
         int lit = s-(P[d1].x-loc);
         int cp1 = dp[d1][1]-min(dp[d1][0],lit);
         int cp2 = dp[d1][2];
         cmp(S1,S2,k,cp1,cp2,0);
     }
}
int main()
{
    while(scanf("%d%d%d%d",&e,&s,&n,&m)==4)
        {
             num[0]=num[1]=num[2]=num[3]=0;
              int k=0;
             for(int i=0; i<n; i++) {
                    scanf("%d%d",&P[k].t,&P[k].x);
                if(P[k].x<e)k++;
            }
            n=k;
             sort(P,P+n);
             if(P[n-1].x!=e)
             {
                 P[n]=point(e,3);
                 n++;
             }
             for(int i=0; i<n; i++)
                if(P[i].t==1) D[ 1 ][num[1]++ ] =i;
                else if(P[i].t==2) D[2][ num[2] ++ ]=i;
                else D[3][ num[3]++ ]=i;
            dp[n-1][0]=dp[n-1][1]=dp[n-1][2]=0;
            for(int i=n-2; i>=0;i--)dp[i][0]=dp[i][1]=dp[i][2]=INF;

            for(int i=n-2; i>=0; i--)
                {
                       if(P[i].t==1)solve1(i);
                       else if(P[i].t==2)solve2(i);
                       else solve3(i);
                       if(dp[i][1]==INF)break;
                }
            for(int i=0;i<m; i++)
            {
                 int S1=INF,S2=INF;
                 int loc;
                 scanf("%d",&loc);
                 solve4(loc,S1,S2);
                 if(S1==INF){
                     printf("-1 -1\n");
                 }else{
                     printf("%d %d\n",S1,S2);
                 }
            }
        }
    return 0;
}
/*
20 1 1
369

*/


#include <bits/stdc++.h>
using namespace std;
const int maxn = 200100;

int e, s, n, m;
vector<int> a;
vector<int> all, butR, onlyS;
vector<pair<int, int>> has;

int id(int x) {
    return lower_bound(a.begin(), a.end(), x) - a.begin();
}

#define DEBU
#ifdef DEBUG
#define debug debug_print
template<class... Arg>
void debug_print(Arg... args) {
    printf(args...);
}
#else
#define debug (void)
#endif

vector<int> cover(int use) {
    debug("call cover: %d\n", use);
    vector<int> res(a.size());
    for (auto x: has) {
        if (x.second >= use) {
            res[id(x.first)] += 1;
            res[id(x.first + s)] -= 1;
        }
    }
    #ifdef DEBUG
    for (auto x: res) {
        debug("%d ", x);
    }puts("");
    #endif

    int prev = 0;
    for (int& i: res) {
        i += prev;
        prev = i;
    }
    #ifdef DEBUG
    for (auto x: res) {
        debug("%d ", x);
    }puts("");
    #endif
    for (size_t i = 0; i < res.size(); i++) {
        if (res[i]) {
            res[i] = a[i+1] - a[i];
        }
    }
    #ifdef DEBUG
    for (auto x: res) {
        debug("%d ", x);
    }puts("");
    #endif
    prev = 0;
    for (int& i: res) {
        i += prev;
        prev = i;
    }
    #ifdef DEBUG
    for (auto x: res) {
        debug("%d ", x);
    }puts("");
    #endif
    return res;
}

pair<int, int> solve(int f) {
    if (f+s >= e) return {0, 0};
    f += s;
    int eAt = id(e) - 1, fAt = id(f) - 1;
    if (all[eAt] - all[fAt] != e-f) return {-1, -1};
    int needR = (e-f) - (butR[eAt] - butR[fAt]);
    int needP = (e-f) - (onlyS[eAt] - onlyS[fAt]) - needR;
    return {needR, needP};
}

int query[maxn];

int main() {
    a.clear();
    scanf("%d%d%d%d", &e, &s, &n, &m);
    a.push_back(e);
    a.push_back(-INT_MAX);

    for (int i = 0; i < n; i++) {
        int t, x;
        scanf("%d%d", &t, &x);
        if (x >= e) continue;
        has.push_back(make_pair(x, t));
        a.push_back(x);
        a.push_back(x+s);
    }

    for (int i = 0; i < m; i++) {
        scanf("%d", &query[i]);
        a.push_back(query[i]);
        a.push_back(query[i] + s);
    }

    sort(a.begin(), a.end());
    a.erase(unique(a.begin(), a.end()), a.end());

    #ifdef DEBUG
    for (auto x: a) {
        printf("%d ", x);
    }puts("");
    #endif

    all = cover(1);
    butR = cover(2);
    onlyS = cover(3);
    for (int i = 0; i < m; i++) {
        pair<int, int> ans = solve(query[i]);
        printf("%d %d\n", ans.first, ans.second);
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
const int maxn = 100100;

int e, s, n, m;
vector<int> a;
vector<int> all, butR, onlyS;
vector<pair<int, int>> has;

int id(int x) {
    return lower_bound(a.begin(), a.end(), x) - a.begin();
}

#define DEBU
#ifdef DEBUG
#define debug debug_print
template<class... Arg>
void debug_print(Arg... args) {
    printf(args...);
}
#else
#define debug (void)
#endif

vector<int> cover(int use) {
    debug("call cover: %d\n", use);
    vector<int> res(a.size());
    for (auto x: has) {
        if (x.second >= use) {
            res[id(x.first)] += 1;
            res[id(x.first + s)] -= 1;
        }
    }
    #ifdef DEBUG
    for (auto x: res) {
        debug("%d ", x);
    }puts("");
    #endif

    int prev = 0;
    for (int& i: res) {
        i += prev;
        prev = i;
    }
    #ifdef DEBUG
    for (auto x: res) {
        debug("%d ", x);
    }puts("");
    #endif
    for (size_t i = 0; i < res.size(); i++) {
        if (res[i]) {
            res[i] = a[i+1] - a[i];
        }
    }
    #ifdef DEBUG
    for (auto x: res) {
        debug("%d ", x);
    }puts("");
    #endif
    prev = 0;
    for (int& i: res) {
        i += prev;
        prev = i;
    }
    #ifdef DEBUG
    for (auto x: res) {
        debug("%d ", x);
    }puts("");
    #endif
    return res;
}

pair<int, int> solve(int f) {
    if (f+s >= e) return {0, 0};
    f += s;
    int eAt = id(e) - 1, fAt = id(f) - 1;
    if (all[eAt] - all[fAt] != e-f) return {-1, -1};
    int needR = (e-f) - (butR[eAt] - butR[fAt]);
    int needP = (e-f) - (onlyS[eAt] - onlyS[fAt]) - needR;
    return {needR, needP};
}

int query[maxn];

int main() {
    a.clear();
    scanf("%d%d%d%d", &e, &s, &n, &m);
    a.push_back(e);
    a.push_back(-INT_MAX);

    for (int i = 0; i < n; i++) {
        int t, x;
        scanf("%d%d", &t, &x);
        if (x >= e) continue;
        has.push_back(make_pair(x, t));
        a.push_back(x);
        a.push_back(x+s);
    }

    for (int i = 0; i < m; i++) {
        scanf("%d", &query[i]);
        a.push_back(query[i]);
        a.push_back(query[i] + s);
    }

    sort(a.begin(), a.end());
    a.erase(unique(a.begin(), a.end()), a.end());

    #ifdef DEBUG
    for (auto x: a) {
        printf("%d ", x);
    }puts("");
    #endif

    all = cover(1);
    butR = cover(2);
    onlyS = cover(3);
    for (int i = 0; i < m; i++) {
        pair<int, int> ans = solve(query[i]);
        printf("%d %d\n", ans.first, ans.second);
    }
    return 0;
}


#include <iostream>
#include <algorithm>

using namespace std;

int arr_sorted[1000000];
int arr_pos[1000000];
int arr_typ[1000000];
int arr_inpPos[1000000];
int arr_fuels[1000000][3];
int size = 0;

bool cmp(int a, int  b) {
    return arr_pos[a] < arr_pos[b] || (arr_pos[a] == arr_pos[b] && arr_typ[a] == 0);
}

void processStops(int s) {
    int last[] = {size -1, size -1, size - 1};
    int first[] = {size -1, size -1, size - 1};

    int in = size-1;

    while (in --) {
        int index = arr_sorted[in];
        int typ_orig = arr_typ[index];
        int typ = typ_orig == 0 ? 3 : typ_orig;
        int pos = arr_pos[index];

        for (int lii = 0; lii < 3; lii ++) {
            int lastType = lii + 1;
            int li = last[lii];
            if (li > in && arr_pos[arr_sorted[li]] > pos + s) {
                while (li >= 0 && ((arr_pos[arr_sorted[li]] > pos + s) || arr_typ[arr_sorted[li]] != lastType))
                    li--;
                last[lii] = li;
            }
        }
        // cout << first[0] << "_" <<  first[1] << "_" << first[2] << endl;
        // cout << last[0] << "_" << last[1] << "_" << last[2] << endl;

        int best = -1;
        for (int i = 0; i < 3; i ++) {
            if (i < typ - 1)
                continue;
            int ind = arr_sorted[first[i]];
            if ((best == -1 || arr_pos[best] > arr_pos[ind]) && arr_pos[ind] <= pos + s)
                best = ind;
        }

        int worse = -1;
        for (int i = 0; i < typ - 1; i ++) {
            int ind = arr_sorted[first[i]];
            if (worse == -1 && arr_pos[ind] <= pos + s) {
                worse = ind;
                break;
            }
        }

        // cout << best << " - " << worse << endl;
        if (best > -1) {
            if (arr_fuels[best][0] > -1) {
                arr_fuels[index][0] = arr_fuels[best][0];
                arr_fuels[index][1] = arr_fuels[best][1];
                arr_fuels[index][typ - 1] = arr_fuels[index][typ - 1] + arr_pos[best] - pos;
            }
        } else if (worse > -1 && arr_fuels[worse][0] > -1) {
                arr_fuels[index][0] = arr_fuels[worse][0];
                arr_fuels[index][1] = arr_fuels[worse][1];
                arr_fuels[index][typ - 1] = arr_fuels[index][typ - 1] + s;
                arr_fuels[index][arr_typ[worse] - 1] = arr_fuels[index][arr_typ[worse] - 1] - (s - ( arr_pos[worse] - pos));
        }

        if (typ_orig > 0)
            first[typ_orig - 1] = in;
        // cout << "AA " << arr_fuels[index][0] << " " << arr_fuels[index][1] << endl;
    }
}

int main() {
    int e, s, n, m;
    cin >> e >> s >> n >> m;

    arr_sorted[0] = 0;
    arr_pos[0] = e; arr_typ[0] =  3; arr_inpPos[0] = 0; arr_fuels[0][0] = 0; arr_fuels[0][1] = 0;   arr_fuels[0][2] = 0;
    int n1 = n;
    int m1 = m;
    size = 1;

    while(n1--) {
        int t, p;
        cin >> t >> p;
        arr_pos[size] = p; arr_typ[size] =  t; arr_inpPos[size] = 0; arr_fuels[size][0] = -1; arr_fuels[size][1] = -1;   arr_fuels[size][2] = 0;
        arr_sorted[size] = size;
        size ++;
    }

    while(m1--) {
        int p;
        cin >> p;
        arr_pos[size] = p; arr_typ[size] =  0; arr_inpPos[size] = m-m1; arr_fuels[size][0] = -1; arr_fuels[size][1] = -1;   arr_fuels[size][2] = 0;
        arr_sorted[size] = size;
        size ++;
    }
    sort(arr_sorted, arr_sorted + size, cmp);

    // cout << "===";
//    for (int i =0 ;i <size; i++) {
//        cout << arr_sorted[i] << " ";
//    }
//    cout << endl;

    processStops(s);
    for(int i = 0; i<m; i++) {
        cout << arr_fuels[n + 1 + i][0] << " " << arr_fuels[n + 1 + i][1] << endl;
    }
}


#include <iostream>
#include <algorithm>

using namespace std;

int arr_sorted[1000000];
int arr_pos[1000000];
int arr_typ[1000000];
int arr_inpPos[1000000];
int arr_fuels[1000000][3];
int size = 0;

bool cmp(int a, int  b) {
    return arr_pos[a] < arr_pos[b] || (arr_pos[a] == arr_pos[b] && arr_typ[a] == 0);
}

void processStops(int s) {
    int in = size-1;

    while (arr_sorted[in] != 0) in--;
    int last[] = {in, in, in};
    int first[] = {in, in, in};

    while (in --) {

        int index = arr_sorted[in];
        int typ_orig = arr_typ[index];
        int typ = typ_orig == 0 ? 3 : typ_orig;
        int pos = arr_pos[index];

        for (int lii = 0; lii < 3; lii ++) {
            int lastType = lii + 1;
            int li = last[lii];
            if (li > in && arr_pos[arr_sorted[li]] > pos + s) {
                while (li >= 0 && ((arr_pos[arr_sorted[li]] > pos + s) || arr_typ[arr_sorted[li]] != lastType))
                    li--;
                last[lii] = li;
            }
        }
        // cout << first[0] << "_" <<  first[1] << "_" << first[2] << endl;
        // cout << last[0] << "_" << last[1] << "_" << last[2] << endl;

        int best = -1;
        for (int i = 0; i < 3; i ++) {
            if (i < typ - 1)
                continue;
            int ind = arr_sorted[first[i]];
            if ((best == -1 || arr_pos[best] > arr_pos[ind]) && arr_pos[ind] <= pos + s)
                best = ind;
        }

        int worse = -1;
        for (int i = 0; i < typ - 1; i ++) {
            int ind = arr_sorted[first[i]];
            if (arr_pos[ind] <= pos + s) {
                worse = ind;
            }
        }

        // cout << best << " - " << worse << endl;
        if (best > -1) {
            if (arr_fuels[best][0] > -1) {
                arr_fuels[index][0] = arr_fuels[best][0];
                arr_fuels[index][1] = arr_fuels[best][1];
                arr_fuels[index][typ - 1] = arr_fuels[index][typ - 1] + arr_pos[best] - pos;
            }
        } else if (worse > -1 && arr_fuels[worse][0] > -1) {
                arr_fuels[index][0] = arr_fuels[worse][0];
                arr_fuels[index][1] = arr_fuels[worse][1];
                arr_fuels[index][typ - 1] = arr_fuels[index][typ - 1] + s;
                arr_fuels[index][arr_typ[worse] - 1] = arr_fuels[index][arr_typ[worse] - 1] - (s - ( arr_pos[worse] - pos));
        }

        if (typ_orig > 0)
            first[typ_orig - 1] = in;
        // cout << "AA " << index << " " <<  arr_fuels[index][0] << " " << arr_fuels[index][1] << endl;
    }
}

int main() {
    int e, s, n, m;
    cin >> e >> s >> n >> m;

    arr_sorted[0] = 0;
    arr_pos[0] = e; arr_typ[0] =  3; arr_inpPos[0] = 0; arr_fuels[0][0] = 0; arr_fuels[0][1] = 0;   arr_fuels[0][2] = 0;
    int n1 = n;
    int m1 = m;
    size = 1;

    while(n1--) {
        int t, p;
        cin >> t >> p;
        arr_pos[size] = p; arr_typ[size] =  t; arr_inpPos[size] = 0; arr_fuels[size][0] = -1; arr_fuels[size][1] = -1;   arr_fuels[size][2] = 0;
        arr_sorted[size] = size;
        size ++;
    }

    while(m1--) {
        int p;
        cin >> p;
        arr_pos[size] = p; arr_typ[size] =  0; arr_inpPos[size] = m-m1; arr_fuels[size][0] = -1; arr_fuels[size][1] = -1;   arr_fuels[size][2] = 0;
        arr_sorted[size] = size;
        size ++;
    }
    sort(arr_sorted, arr_sorted + size, cmp);

//    cout << "===";
//    for (int i =0 ;i <size; i++) {
//        cout << arr_sorted[i] << " ";
//    }
//    cout << endl;

    processStops(s);
    for(int i = 0; i<m; i++) {
        cout << arr_fuels[n + 1 + i][0] << " " << arr_fuels[n + 1 + i][1] << endl;
    }
}


#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<stack>
#include<cstdlib>
#include<string>
#include<bitset>
#define INF 1000000000
#define N 200005
#define fi first
#define se second
#define debug(x) cout<<#x<<"="<<x<<endl
#define MP(x,y) make_pair(x,y)
using namespace std;
typedef long long LL;
typedef pair<int,int> pii;
int s1[N],s2[N];
vector<int> pr,sp,sd;
int main()
{
    int e,s,n,m,x,t,f,i,n1=0,n2=0,n3=0,lim,loc,ans1,ans2,ans3;
    cin>>e>>s>>n>>m;
    for(i=1;i<=n+1;i++)
    {
        if(i==n+1)
            x=3,t=e;
        else
        {
            cin>>x>>t;
            if(t>=e) continue;
        }
        if(x==3)
            sp.push_back(t),n3++;
        if(x>=2)
            pr.push_back(t),n2++;
        sd.push_back(t),n1++;
    }
    //debug(n1);
    sort(sp.begin(),sp.end());
    sort(pr.begin(),pr.end());
    sort(sd.begin(),sd.end());
    for(i=n1-2;i>=0;i--)
        if(sd[i+1]-sd[i]>s)
        {
            lim=sd[i+1]-s;
            break;
        }
    if(i==-1)
        lim=sd[0]-s;
    //debug(lim);
    s2[n3-1]=0;
    for(i=n3-2;i>=0;i--)
        s2[i]=s2[i+1]+max(sp[i+1]-sp[i]-s,0);
    s1[n2-1]=0;
    for(i=n2-2;i>=0;i--)
        s1[i]=s1[i+1]+max(pr[i+1]-pr[i]-s,0);
    while(m--)
    {
        scanf("%d",&f);
        if(f<lim)
            printf("-1 -1\n");
        else
        {
            loc=lower_bound(sp.begin(),sp.end(),f)-sp.begin();
            ans2=(s2[loc]+max(sp[loc]-f-s,0));
            ans3=(e-f)-ans2;
            loc=lower_bound(pr.begin(),pr.end(),f)-pr.begin();
            ans1=s1[loc]+max(pr[loc]-f-s,0);
            ans2-=ans1;
            printf("%d %d\n",ans1,ans2);
        }
    }
    return 0;
}
// davidlee1999WTK 2015/
// srO myk Orz
//ios::sync_with_stdio(false);
//#pragma comment(linker, "/STACK:102400000,102400000")
//#define O2 __attribute__((optimize("-O2")))


#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <set>
#include <map>
#include <queue>
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstring>
#include <cctype>
#include <cassert>
#include <limits>
#include <functional>
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define rer(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i))
#define reu(i,l,u) for(int (i)=(int)(l);(i)<(int)(u);++(i))
#if defined(_MSC_VER) || __cplusplus > 199711L
#define aut(r,v) auto r = (v)
#else
#define aut(r,v) __typeof(v) r = (v)
#endif
#define each(it,o) for(aut(it, (o).begin()); it != (o).end(); ++ it)
#define all(o) (o).begin(), (o).end()
#define pb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))
#define mset(m,v) memset(m,v,sizeof(m))
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL
using namespace std;
typedef vector<int> vi; typedef pair<int,int> pii; typedef vector<pair<int,int> > vpii; typedef long long ll;
template<typename T, typename U> inline void amin(T &x, U y) { if(y < x) x = y; }
template<typename T, typename U> inline void amax(T &x, U y) { if(x < y) x = y; }

int main() {
	int e; int s; int n; int m;
	while(~scanf("%d%d%d%d", &e, &s, &n, &m)) {
		vpii v(n);
		rep(i, n) {
			int t, p;
			scanf("%d%d", &t, &p), -- t;
			v[i] = mp(t, p);
		}
		vi queries(m);
		rep(i, m)
			scanf("%d", &queries[i]);
		vi poses;
		rep(i, n) {
			int p = v[i].second;
			poses.push_back(p);
			poses.push_back(p + s);
		}
		rep(i, m) {
			poses.push_back(queries[i]);
			poses.push_back(queries[i] + s);
		}
		poses.push_back(e);
		sort(poses.begin(), poses.end());
		poses.erase(unique(poses.begin(), poses.end()), poses.end());
		int P = poses.size();
		vector<vector<int> > cnts(3, vector<int>(P+1));
		rep(i, n) {
			int l = lower_bound(poses.begin(), poses.end(), v[i].second) - poses.begin();
			int r = lower_bound(poses.begin(), poses.end(), v[i].second + s) - poses.begin();
			rep(j, v[i].first + 1) {
				++ cnts[j][l];
				-- cnts[j][r];
			}
		}
		vector<vector<ll> > sums(3, vector<ll>(P+1));
		rep(i, 3) {
			rep(j, P)
				cnts[i][j + 1] += cnts[i][j];
			rep(j, P)
				sums[i][j + 1] = sums[i][j] + (j + 1 < P && cnts[i][j] > 0 ? poses[j + 1] - poses[j] : 0);
		}
		int goal = lower_bound(poses.begin(), poses.end(), e) - poses.begin();
		rep(i, m) {
			int a = lower_bound(poses.begin(), poses.end(), queries[i] + s) - poses.begin();
			ll ans1, ans2;
			if(goal <= a) {
				ans1 = ans2 = 0;
			} else {
				ll dist = (ll)poses[goal] - poses[a];
				ll x2 = sums[2][goal] - sums[2][a];
				ll x1 = sums[1][goal] - sums[1][a];
				ll x0 = sums[0][goal] - sums[0][a];
				if(x2 == dist) {
					ans1 = ans2 = 0;
				} else if(x1 == dist) {
					ans1 = 0;
					ans2 = dist - x2;
				} else if(x0 == dist) {
					ans1 = dist - x1;
					ans2 = (dist - x2) - ans1;
					assert(ans2 >= 0);
				} else {
					ans1 = ans2 = -1;
				}
			}
			printf("%I64d %I64d\n", ans1, ans2);
		}
	}
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<ll> vi;
typedef vector<ii> vii;

struct sol {
	ll x,y,z,a,b,t;
};

vii stations;
vector<sol> sols;
ll e,s,n,m;

sol driveback(sol car, ll si, ll fin) {
	ll dist=stations[si].first-fin;

	ll i;
	i=max(min(car.z,min(s-car.t,dist-car.t)),(ll)0);
	car.z-=i;
	car.t+=i;

	i=max(min(car.y,min(s-car.t,dist-car.t)),(ll)0);
	car.y-=i;
	car.t+=i;
	car.b+=i;

	i=max(min(car.x,min(s-car.t,dist-car.t)),(ll)0);
	car.x-=i;
	car.t+=i;
	car.a+=i;

	if (dist>car.t) {
		car.a=car.b=-1;
		car.x=car.y=car.z=0;
		car.t=0;
		return car;
	}

	i=s-car.t;
	car.z=min(i,car.z);
	i-=car.z;
	car.y=min(i,car.y);
	i-=car.y;
	car.x=min(i,car.x);

	car.t-=dist;
	return car;
}

int main() {
	cin >> e >> s >> n >> m;
	ll i,j;
	for (ll c=0;c<n;c++) {
		cin >> i >> j;
		stations.push_back(ii(j,i));
	}
	stations.push_back(ii(ii(e,3)));
	sort(stations.begin(),stations.end());
	sols.resize(n+1);
	sol car;
	car.x = car.y = car.z = car.a = car.b = 0;
	car.t=s;
	sols[n]=car;

	for (ll c=n-1;c>=0;c--) {
		car = driveback(car, c+1, stations[c].first);
		if (car.a!=-1) {
			ll t=stations[c].second;
			switch (t) {
				case 1:
					car.x=s;
					break;
				case 2:
					car.y=s;
					break;
				case 3:
					car.z=s;
					break;
			}
		}
		sols[c]=car;
	}

	for (ll c=0;c<m;c++) {
		cin >> i;
		vii::iterator it = upper_bound(stations.begin(),stations.end(),ii(i,3));
		car = driveback(sols[it-stations.begin()],it-stations.begin(),i);
		cout << car.a << ' ' << car.b << endl;
	}
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef pair<int,int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;

struct sol {
	int x,y,z,a,b,t;
};

vii stations;
vector<sol> sols;
int e,s,n,m;

sol driveback(sol car, int si, int fin) {
	int dist=stations[si].first-fin;

	int i;
	i=max(min(car.z,min(s-car.t,dist-car.t)),0);
	car.z-=i;
	car.t+=i;

	i=max(min(car.y,min(s-car.t,dist-car.t)),0);
	car.y-=i;
	car.t+=i;
	car.b+=i;

	i=max(min(car.x,min(s-car.t,dist-car.t)),0);
	car.x-=i;
	car.t+=i;
	car.a+=i;

	if (dist>car.t) {
		car.a=car.b=-1;
		car.x=car.y=car.z=0;
		car.t=0;
		return car;
	}

	i=s-car.t;
	car.z=min(i,car.z);
	i-=car.z;
	car.y=min(i,car.y);
	i-=car.y;
	car.x=min(i,car.x);

	car.t-=dist;
	return car;
}

int main() {
	cin >> e >> s >> n >> m;
	int i,j;
	for (int c=0;c<n;c++) {
		cin >> i >> j;
		stations.push_back(ii(j,i));
	}
	stations.push_back(ii(ii(e,3)));
	sort(stations.begin(),stations.end());
	sols.resize(n+1);
	sol car;
	car.x = car.y = car.z = car.a = car.b = 0;
	car.t=s;
	sols[n]=car;

	for (int c=n-1;c>=0;c--) {
		car = driveback(car, c+1, stations[c].first);
		if (car.a!=-1) {
			int t=stations[c].second;
			switch (t) {
				case 1:
					car.x=s;
					break;
				case 2:
					car.y=s;
					break;
				case 3:
					car.z=s;
					break;
			}
		}
		sols[c]=car;
	}

	for (int c=0;c<m;c++) {
		cin >> i;
		vii::iterator it = upper_bound(stations.begin(),stations.end(),ii(i,3));
		car = driveback(sols[it-stations.begin()],it-stations.begin(),i);
		cout << car.a << ' ' << car.b << endl;
	}
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef pair<int,int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;

struct sol {
	int x,y,z,a,b,t;
};

vii stations;
vector<sol> sols;
int e,s,n,m;

sol driveback(sol car, int si, int fin) {
	int dist=stations[si].first-fin;

	int i;
	i=max(min(car.z,min(s-car.t,dist-car.t)),0);
	car.z-=i;
	car.t+=i;

	i=max(min(car.y,min(s-car.t,dist-car.t)),0);
	car.y-=i;
	car.t+=i;
	car.b+=i;

	i=max(min(car.x,min(s-car.t,dist-car.t)),0);
	car.x-=i;
	car.t+=i;
	car.a+=i;

	if (dist>car.t) {
		car.a=car.b=-1;
		car.x=car.y=car.z=0;
		car.t=0;
		return car;
	}

	i=s-car.t;
	car.z=min(i,car.z);
	i-=car.z;
	car.y=min(i,car.y);
	i-=car.y;
	car.x=min(i,car.x);

	car.t-=dist;
	return car;
}

int main() {
	cin >> e >> s >> n >> m;
	int i,j;
	for (int c=0;c<n;c++) {
		cin >> i >> j;
		if (j<=e)
		stations.push_back(ii(j,i));
	}
	n=stations.size();
	stations.push_back(ii(ii(e,3)));
	sort(stations.begin(),stations.end());
	sols.resize(n+1);
	sol car;
	car.x = car.y = car.z = car.a = car.b = 0;
	car.t=s;
	sols[n]=car;

	for (int c=n-1;c>=0;c--) {
		car = driveback(car, c+1, stations[c].first);
		if (car.a!=-1) {
			int t=stations[c].second;
			switch (t) {
				case 1:
					car.x=s;
					break;
				case 2:
					car.y=s;
					break;
				case 3:
					car.z=s;
					break;
			}
		}
		sols[c]=car;
	}

	for (int c=0;c<m;c++) {
		cin >> i;
		vii::iterator it = upper_bound(stations.begin(),stations.end(),ii(i,3));
		car = driveback(sols[it-stations.begin()],it-stations.begin(),i);
		cout << car.a << ' ' << car.b << endl;
	}
	return 0;
}


#include <algorithm>
#include <iostream>
#include <sstream>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <cmath>
#include <list>
#include <cassert>
#include <ctime>
#include <climits>
using namespace std;

#define PB push_back
#define MP make_pair
#define SZ(v) ((int)(v).size())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)
#define REPE(i,n) FORE(i,0,n)
#define FORSZ(i,a,v) FOR(i,a,SZ(v))
#define REPSZ(i,v) REP(i,SZ(v))
typedef long long ll;
typedef unsigned long long ull;
ll gcd(ll a,ll b) { return b==0?a:gcd(b,a%b); }

const int MAXG=200000;
const int MAXQ=200000;
const int MAXN=MAXG+MAXQ+1;

typedef struct P { int x,type,qi; } P;
bool operator<(const P &a,const P &b) { return a.x<b.x; }

int tx,cap,ng,nq,n;
P p[MAXN];

int need[MAXN][3],opt[MAXN][3]; bool ok[MAXN];
int ret[MAXQ][3];

void run() {
	scanf("%d%d%d%d",&tx,&cap,&ng,&nq);
	REP(i,ng) scanf("%d%d",&p[i].type,&p[i].x),--p[i].type,p[i].qi=-1;
	REP(i,nq) scanf("%d",&p[ng+i].x),p[ng+i].type=2,p[ng+i].qi=i;
	p[ng+nq].x=tx; p[ng+nq].type=-1,p[ng+nq].qi=-1;
	n=ng+nq+1; sort(p,p+n);

	int to=n-1; while(p[to].type!=-1) --to; ok[to]=true;
	REP(i,3) need[to][i]=0,opt[to][i]=0;
	for(int at=to-1;at>=0;--at) {
		int dx=p[to].x-p[at].x;
		REP(i,3) opt[at][i]=opt[to][i],need[at][i]=need[to][i]; ok[at]=ok[to];
		REPE(i,p[at].type) { int cur=max(0,min(opt[at][i],cap-dx)); dx+=cur; opt[at][i]-=cur; }
		if(dx==cap) REP(i,3) need[at][i]+=opt[at][i],opt[at][i]=0; if(dx>cap) ok[at]=false; else opt[at][p[at].type]+=dx;
		if(p[at].qi!=-1) {
			REP(i,3) need[at][i]+=opt[at][i],opt[at][i]=0;
			REP(i,3) ret[p[at].qi][i]=ok[at]?need[at][i]:-1;
		} else {
			int sum=0; REP(i,3) sum+=opt[at][i];
			for(int i=2;i>=0;--i) { int cur=min(opt[at][i],sum-cap); need[at][i]+=cur; opt[at][i]-=cur; sum-=cur; }
			to=at;
		}
		//printf("\t%d: %c [%d,%d,%d] [%d,%d,%d]\n",p[at].x,ok?'V':'X',opt[at][0],opt[at][1],opt[at][2],need[at][0],need[at][1],need[at][2]);
	}
	REP(i,nq) printf("%d %d\n",ret[i][0],ret[i][1]);
}

int main() {
	run();
	return 0;
}


#include <bits/stdc++.h>
#include <stdint.h>
using namespace std;

typedef uint8_t byte;
typedef int16_t i16;
typedef uint16_t ui16;
typedef int32_t i32;
typedef uint32_t ui32;
typedef int64_t i64;
typedef uint64_t ui64;
typedef long double ld;
typedef pair<int, int> Pii;

#ifdef __CLANG
	#define unordered_map map
	#define unordered_set set
#endif

int gcdex(int a, int b, int &x, int &y) {
	if (a == 0) {
		x = 0;
		y = 1;
		return b;
	}

	int x1, y1;
	int g = gcdex(b % a, a, x1, y1);
	x = y1 - (b / a) * x1;
	y = x1;

	return g;
}

#define MOD 1000000007
inline int ADD_MOD(int a, int b) { return (a + b) % MOD; }
inline int MUL_MOD(int a, int b) { return (i64(a) * b) % MOD; }
inline int SUB_MOD(int a, int b) { return a >= b ? a - b : a + MOD - b; }
int DIV_MOD(int a, int b) {
	int x, y;
	gcdex(b, MOD, x, y);

	int b1 = (x % MOD + MOD) % MOD;
	return MUL_MOD(a, b1);
}

const double EPS = 1. / 1e9;
inline bool EPS_EQUAL(double a, double b) { return abs(a - b) <= EPS; }
inline bool EPS_LESS(double a, double b) { return b - a > EPS; }
inline bool EPS_GREATER(double a, double b) { return a - b > EPS; }

const int INF = 2e9;

int s;
vector<int> x[3];
vector<Pii> costs[3];

int maxIndex(int ar[3]) {
	int vals[3];
	for (int i = 0; i < 3; ++i) {
		vals[i] = ar[i] >= 0 ? x[i][ar[i]] : -INF;
	}

	if (vals[0] > max(vals[1], vals[2])) {
		return 0;
	}
	if (vals[1] > vals[2]) {
		return 1;
	}
	return 2;
}

int farthest(vector<int> &a, int from) {
	int index = upper_bound(a.begin(), a.end(), from + s) - a.begin() - 1;
	if (index < 0) {
		return -1;
	}
	if (a[index] > from && a[index] - from <= s) {
		return index;
	}
	return -1;
}

int nearest(vector<int> &a, int from) {
	int index = upper_bound(a.begin(), a.end(), from) - a.begin();
	if (index == a.size()) {
		return -1;
	}
	if (a[index] - from <= s) {
		return index;
	}
	return -1;
}

Pii calc_cost(int from, int type) {
	int near2 = nearest(x[2], from);
	int near1 = nearest(x[1], from);
	int far1 = farthest(x[1], from);
	int far0 = farthest(x[0], from);

	// cout << "find cost for " << from << " [" << type << "]"
	// 	<< ": near2: " << near2
	// 	<< ", near1: " << near1
	// 	<< ", far1: " << far1
	// 	<< ", far0: " << far0;

	if (type == 2) {
		if (near2 >= 0) return costs[2][near2];
		if (far1 >= 0) {
			auto &c = costs[1][far1];
			return {c.first, c.second - (s - x[1][far1] + from)};
		}
		if (far0 >= 0) {
			auto &c = costs[0][far0];
			return {c.first - (s - x[0][far0] + from), c.second};
		}
	}
	if (type == 1) {
		if (near2 >= 0) {
			auto &c = costs[2][near2];
			return {c.first, c.second + (x[2][near2] - from)};
		}
		if (far1 >= 0) {
			auto &c = costs[1][far1];
			return {c.first, c.second + (x[1][far1] - from)};
		}
		if (far0 >= 0) {
			auto &c = costs[0][far0];
			return {c.first - (s - (x[0][far0] - from)), c.second + s};
		}
	}
	if (type == 0) {
		if (near2 >= 0 && (near1 < 0 || x[1][near1] > x[2][near2])) {
			auto &c = costs[2][near2];
			return {c.first + (x[2][near2] - from), c.second};
		}
		if (near1 >= 0) {
			auto &c = costs[1][near1];
			return {c.first + (x[1][near1] - from), c.second};
		}
		if (far0 >= 0) {
			auto &c = costs[0][far0];
			return {c.first + (x[0][far0] - from), c.second};
		}
	}
	return {-1, -1};
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.precision(15);

	int f, n, m;
	cin >> f >> s >> n >> m;

	x[2].push_back(f);

	int realN = 1;
	for (int i = 0; i < n; ++i) {
		int t, x0;
		cin >> t >> x0;

		if (x0 < f) {
			++realN;
			x[t - 1].push_back(x0);
		}
	}

	int last[3];
	for (int i = 0; i < 3; ++i) {
		sort(x[i].begin(), x[i].end());
		last[i] = x[i].size() - 1;
		costs[i].resize(x[i].size(), {-1, -1});
	}

	costs[2][last[2]] = {0, 0};
	last[2]--;

	for (int i = 1; i < realN; ++i) {
		int curType = maxIndex(last);

		Pii cost = calc_cost(x[curType][last[curType]], curType);
		// cout << " = " << cost.first << ":" << cost.second << endl;

		if (cost.first < 0) {
			break;
		}

		costs[curType][last[curType]] = cost;
		last[curType]--;
	}

	for (int i = 0; i < m; ++i) {
		int from;
		cin >> from;

		Pii cost = calc_cost(from, 2);
		if (cost.first < 0 || cost.second < 0) {
			cout << "-1 -1" << endl;
		} else {
			cout << cost.first << " " << cost.second << endl;
		}
	}

	return 0;
}


#include <bits/stdc++.h>
#include <stdint.h>
using namespace std;

typedef uint8_t byte;
typedef int16_t i16;
typedef uint16_t ui16;
typedef int32_t i32;
typedef uint32_t ui32;
typedef int64_t i64;
typedef uint64_t ui64;
typedef long double ld;
typedef pair<int, int> Pii;

#ifdef __CLANG
	#define unordered_map map
	#define unordered_set set
#endif

int gcdex(int a, int b, int &x, int &y) {
	if (a == 0) {
		x = 0;
		y = 1;
		return b;
	}

	int x1, y1;
	int g = gcdex(b % a, a, x1, y1);
	x = y1 - (b / a) * x1;
	y = x1;

	return g;
}

#define MOD 1000000007
inline int ADD_MOD(int a, int b) { return (a + b) % MOD; }
inline int MUL_MOD(int a, int b) { return (i64(a) * b) % MOD; }
inline int SUB_MOD(int a, int b) { return a >= b ? a - b : a + MOD - b; }
int DIV_MOD(int a, int b) {
	int x, y;
	gcdex(b, MOD, x, y);

	int b1 = (x % MOD + MOD) % MOD;
	return MUL_MOD(a, b1);
}

const double EPS = 1. / 1e9;
inline bool EPS_EQUAL(double a, double b) { return abs(a - b) <= EPS; }
inline bool EPS_LESS(double a, double b) { return b - a > EPS; }
inline bool EPS_GREATER(double a, double b) { return a - b > EPS; }

const int INF = 2e9;

int s;
vector<int> x[3];
vector<Pii> costs[3];

int maxIndex(int ar[3]) {
	int vals[3];
	for (int i = 0; i < 3; ++i) {
		vals[i] = ar[i] >= 0 ? x[i][ar[i]] : -INF;
	}

	if (vals[0] > max(vals[1], vals[2])) {
		return 0;
	}
	if (vals[1] > vals[2]) {
		return 1;
	}
	return 2;
}

int farthest(vector<int> &a, int from) {
	int index = upper_bound(a.begin(), a.end(), from + s) - a.begin() - 1;
	if (index < 0) {
		return -1;
	}
	if (a[index] > from && a[index] - from <= s) {
		return index;
	}
	return -1;
}

int nearest(vector<int> &a, int from) {
	int index = upper_bound(a.begin(), a.end(), from) - a.begin();
	if (index == a.size()) {
		return -1;
	}
	if (a[index] - from <= s) {
		return index;
	}
	return -1;
}

Pii calc_cost(int from, int type) {
	int near2 = nearest(x[2], from);
	int near1 = nearest(x[1], from);
	int far1 = farthest(x[1], from);
	int far0 = farthest(x[0], from);

	// cout << "find cost for " << from << endl;
	// cout << "near2: " << near2 << endl;
	// cout << "near1: " << near1 << endl;
	// cout << "far1: " << far1 << endl;
	// cout << "far0: " << far0 << endl;

	if (type == 2) {
		if (near2 >= 0) return costs[2][near2];
		if (far1 >= 0) {
			auto &c = costs[1][far1];
			return {c.first, c.second - (s - x[1][far1] + from)};
		}
		if (far0 >= 0) {
			auto &c = costs[0][far0];
			return {c.first - (s - x[0][far0] + from), c.second};
		}
	}
	if (type == 1) {
		if (near2 >= 0) {
			auto &c = costs[2][near2];
			return {c.first, c.second + (x[2][near2] - from)};
		}
		if (far1 >= 0) {
			auto &c = costs[1][far1];
			return {c.first, c.second + (x[1][far1] - from)};
		}
		if (far0 >= 0) {
			auto &c = costs[0][far0];
			return {c.first, c.second + (x[0][far0] - from)};
		}
	}
	if (type == 0) {
		if (near2 >= 0) {
			auto &c = costs[2][near2];
			return {c.first + (x[2][near2] - from), c.second};
		}
		if (near1 >= 0) {
			auto &c = costs[1][near1];
			return {c.first + (x[1][near1] - from), c.second};
		}
		if (far0 >= 0) {
			auto &c = costs[0][far0];
			return {c.first + (x[0][far0] - from), c.second};
		}
	}
	return {-1, -1};
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.precision(15);

	int f, n, m;
	cin >> f >> s >> n >> m;

	x[2].push_back(f);

	int realN = 1;
	for (int i = 0; i < n; ++i) {
		int t, x0;
		cin >> t >> x0;

		if (x0 < f) {
			++realN;
			x[t - 1].push_back(x0);
		}
	}

	int last[3];
	for (int i = 0; i < 3; ++i) {
		sort(x[i].begin(), x[i].end());
		last[i] = x[i].size() - 1;
		costs[i].resize(x[i].size(), {-1, -1});
	}

	costs[2][last[2]] = {0, 0};
	last[2]--;

	for (int i = 1; i < realN; ++i) {
		int curType = maxIndex(last);

		Pii cost = calc_cost(x[curType][last[curType]], curType);
		// cout << cost.first << ":" << cost.second << endl;

		if (cost.first < 0) {
			break;
		}

		costs[curType][last[curType]] = cost;
		last[curType]--;
	}

	for (int i = 0; i < m; ++i) {
		int from;
		cin >> from;

		Pii cost = calc_cost(from, 2);
		if (cost.first < 0 || cost.second < 0) {
			cout << "-1 -1" << endl;
		} else {
			cout << cost.first << " " << cost.second << endl;
		}
	}

	return 0;
}


#include <bits/stdc++.h>
#include <stdint.h>
using namespace std;

typedef uint8_t byte;
typedef int16_t i16;
typedef uint16_t ui16;
typedef int32_t i32;
typedef uint32_t ui32;
typedef int64_t i64;
typedef uint64_t ui64;
typedef long double ld;
typedef pair<int, int> Pii;

#ifdef __CLANG
	#define unordered_map map
	#define unordered_set set
#endif

int gcdex(int a, int b, int &x, int &y) {
	if (a == 0) {
		x = 0;
		y = 1;
		return b;
	}

	int x1, y1;
	int g = gcdex(b % a, a, x1, y1);
	x = y1 - (b / a) * x1;
	y = x1;

	return g;
}

#define MOD 1000000007
inline int ADD_MOD(int a, int b) { return (a + b) % MOD; }
inline int MUL_MOD(int a, int b) { return (i64(a) * b) % MOD; }
inline int SUB_MOD(int a, int b) { return a >= b ? a - b : a + MOD - b; }
int DIV_MOD(int a, int b) {
	int x, y;
	gcdex(b, MOD, x, y);

	int b1 = (x % MOD + MOD) % MOD;
	return MUL_MOD(a, b1);
}

const double EPS = 1. / 1e9;
inline bool EPS_EQUAL(double a, double b) { return abs(a - b) <= EPS; }
inline bool EPS_LESS(double a, double b) { return b - a > EPS; }
inline bool EPS_GREATER(double a, double b) { return a - b > EPS; }

const int INF = 2e9;

int s;
vector<int> x[3];
vector<Pii> costs[3];

int maxIndex(int ar[3]) {
	int vals[3];
	for (int i = 0; i < 3; ++i) {
		vals[i] = ar[i] >= 0 ? x[i][ar[i]] : -INF;
	}

	if (vals[0] > max(vals[1], vals[2])) {
		return 0;
	}
	if (vals[1] > vals[2]) {
		return 1;
	}
	return 2;
}

int farthest(vector<int> &a, int from) {
	int index = upper_bound(a.begin(), a.end(), from + s) - a.begin() - 1;
	if (index < 0) {
		return -1;
	}
	if (a[index] > from && a[index] - from <= s) {
		return index;
	}
	return -1;
}

int nearest(vector<int> &a, int from) {
	int index = upper_bound(a.begin(), a.end(), from) - a.begin();
	if (index == a.size()) {
		return -1;
	}
	if (a[index] - from <= s) {
		return index;
	}
	return -1;
}

Pii calc_cost(int from, int type) {
	int near2 = nearest(x[2], from);
	int near1 = nearest(x[1], from);
	int far1 = farthest(x[1], from);
	int far0 = farthest(x[0], from);

	// cout << "find cost for " << from << endl;
	// cout << "near2: " << near2 << endl;
	// cout << "near1: " << near1 << endl;
	// cout << "far1: " << far1 << endl;
	// cout << "far0: " << far0 << endl;

	if (type == 2) {
		if (near2 >= 0) return costs[2][near2];
		if (far1 >= 0) {
			auto &c = costs[1][far1];
			return {c.first, c.second - (s - x[1][far1] + from)};
		}
		if (far0 >= 0) {
			auto &c = costs[0][far0];
			return {c.first - (s - x[0][far0] + from), c.second};
		}
	}
	if (type == 1) {
		if (near2 >= 0) {
			auto &c = costs[2][near2];
			return {c.first, c.second + (x[2][near2] - from)};
		}
		if (far1 >= 0) {
			auto &c = costs[1][far1];
			return {c.first, c.second + (x[1][far1] - from)};
		}
		if (far0 >= 0) {
			auto &c = costs[0][far0];
			return {c.first, c.second + (x[0][far0] - from)};
		}
	}
	if (type == 0) {
		if (near2 >= 0 && (near1 < 0 || near1 > near2)) {
			auto &c = costs[2][near2];
			return {c.first + (x[2][near2] - from), c.second};
		}
		if (near1 >= 0) {
			auto &c = costs[1][near1];
			return {c.first + (x[1][near1] - from), c.second};
		}
		if (far0 >= 0) {
			auto &c = costs[0][far0];
			return {c.first + (x[0][far0] - from), c.second};
		}
	}
	return {-1, -1};
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.precision(15);

	int f, n, m;
	cin >> f >> s >> n >> m;

	x[2].push_back(f);

	int realN = 1;
	for (int i = 0; i < n; ++i) {
		int t, x0;
		cin >> t >> x0;

		if (x0 < f) {
			++realN;
			x[t - 1].push_back(x0);
		}
	}

	int last[3];
	for (int i = 0; i < 3; ++i) {
		sort(x[i].begin(), x[i].end());
		last[i] = x[i].size() - 1;
		costs[i].resize(x[i].size(), {-1, -1});
	}

	costs[2][last[2]] = {0, 0};
	last[2]--;

	for (int i = 1; i < realN; ++i) {
		int curType = maxIndex(last);

		Pii cost = calc_cost(x[curType][last[curType]], curType);
		// cout << cost.first << ":" << cost.second << endl;

		if (cost.first < 0) {
			break;
		}

		costs[curType][last[curType]] = cost;
		last[curType]--;
	}

	for (int i = 0; i < m; ++i) {
		int from;
		cin >> from;

		Pii cost = calc_cost(from, 2);
		if (cost.first < 0 || cost.second < 0) {
			cout << "-1 -1" << endl;
		} else {
			cout << cost.first << " " << cost.second << endl;
		}
	}

	return 0;
}


#include <bits/stdc++.h>
#include <stdint.h>
using namespace std;

typedef uint8_t byte;
typedef int16_t i16;
typedef uint16_t ui16;
typedef int32_t i32;
typedef uint32_t ui32;
typedef int64_t i64;
typedef uint64_t ui64;
typedef long double ld;
typedef pair<int, int> Pii;

#ifdef __CLANG
	#define unordered_map map
	#define unordered_set set
#endif

int gcdex(int a, int b, int &x, int &y) {
	if (a == 0) {
		x = 0;
		y = 1;
		return b;
	}

	int x1, y1;
	int g = gcdex(b % a, a, x1, y1);
	x = y1 - (b / a) * x1;
	y = x1;

	return g;
}

#define MOD 1000000007
inline int ADD_MOD(int a, int b) { return (a + b) % MOD; }
inline int MUL_MOD(int a, int b) { return (i64(a) * b) % MOD; }
inline int SUB_MOD(int a, int b) { return a >= b ? a - b : a + MOD - b; }
int DIV_MOD(int a, int b) {
	int x, y;
	gcdex(b, MOD, x, y);

	int b1 = (x % MOD + MOD) % MOD;
	return MUL_MOD(a, b1);
}

const double EPS = 1. / 1e9;
inline bool EPS_EQUAL(double a, double b) { return abs(a - b) <= EPS; }
inline bool EPS_LESS(double a, double b) { return b - a > EPS; }
inline bool EPS_GREATER(double a, double b) { return a - b > EPS; }

const int INF = 2e9;

int s;
vector<int> x[3];
vector<Pii> costs[3];

int maxIndex(int ar[3]) {
	int vals[3];
	for (int i = 0; i < 3; ++i) {
		vals[i] = ar[i] >= 0 ? x[i][ar[i]] : -INF;
	}

	if (vals[0] > max(vals[1], vals[2])) {
		return 0;
	}
	if (vals[1] > vals[2]) {
		return 1;
	}
	return 2;
}

int farthest(vector<int> &a, int from) {
	int index = upper_bound(a.begin(), a.end(), from + s) - a.begin() - 1;
	if (index < 0) {
		return -1;
	}
	if (a[index] > from && a[index] - from <= s) {
		return index;
	}
	return -1;
}

int nearest(vector<int> &a, int from) {
	int index = upper_bound(a.begin(), a.end(), from) - a.begin();
	if (index == a.size()) {
		return -1;
	}
	if (a[index] - from <= s) {
		return index;
	}
	return -1;
}

Pii calc_cost(int from, int type) {
	int near2 = nearest(x[2], from);
	int near1 = nearest(x[1], from);
	int far1 = farthest(x[1], from);
	int far0 = farthest(x[0], from);

	// cout << "find cost for " << from << " [" << type << "]"
	// 	<< ": near2: " << near2
	// 	<< ", near1: " << near1
	// 	<< ", far1: " << far1
	// 	<< ", far0: " << far0;

	if (type == 2) {
		if (near2 >= 0) return costs[2][near2];
		if (far1 >= 0) {
			auto &c = costs[1][far1];
			return {c.first, c.second - (s - x[1][far1] + from)};
		}
		if (far0 >= 0) {
			auto &c = costs[0][far0];
			return {c.first - (s - x[0][far0] + from), c.second};
		}
	}
	if (type == 1) {
		if (near2 >= 0) {
			auto &c = costs[2][near2];
			return {c.first, c.second + (x[2][near2] - from)};
		}
		if (far1 >= 0) {
			auto &c = costs[1][far1];
			return {c.first, c.second + (x[1][far1] - from)};
		}
		if (far0 >= 0) {
			auto &c = costs[0][far0];
			return {c.first - (s - (x[0][far0] - from)), c.second + s};
		}
	}
	if (type == 0) {
		if (near2 >= 0 && (near1 < 0 || near1 > near2)) {
			auto &c = costs[2][near2];
			return {c.first + (x[2][near2] - from), c.second};
		}
		if (near1 >= 0) {
			auto &c = costs[1][near1];
			return {c.first + (x[1][near1] - from), c.second};
		}
		if (far0 >= 0) {
			auto &c = costs[0][far0];
			return {c.first + (x[0][far0] - from), c.second};
		}
	}
	return {-1, -1};
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.precision(15);

	int f, n, m;
	cin >> f >> s >> n >> m;

	x[2].push_back(f);

	int realN = 1;
	for (int i = 0; i < n; ++i) {
		int t, x0;
		cin >> t >> x0;

		if (x0 < f) {
			++realN;
			x[t - 1].push_back(x0);
		}
	}

	int last[3];
	for (int i = 0; i < 3; ++i) {
		sort(x[i].begin(), x[i].end());
		last[i] = x[i].size() - 1;
		costs[i].resize(x[i].size(), {-1, -1});
	}

	costs[2][last[2]] = {0, 0};
	last[2]--;

	for (int i = 1; i < realN; ++i) {
		int curType = maxIndex(last);

		Pii cost = calc_cost(x[curType][last[curType]], curType);
		// cout << " = " << cost.first << ":" << cost.second << endl;

		if (cost.first < 0) {
			break;
		}

		costs[curType][last[curType]] = cost;
		last[curType]--;
	}

	for (int i = 0; i < m; ++i) {
		int from;
		cin >> from;

		Pii cost = calc_cost(from, 2);
		if (cost.first < 0 || cost.second < 0) {
			cout << "-1 -1" << endl;
		} else {
			cout << cost.first << " " << cost.second << endl;
		}
	}

	return 0;
}


#include <bits/stdc++.h>
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define REP(I, N) for (int I = 0; I < (N); ++I)
#define REPP(I, A, B) for (int I = (A); I < (B); ++I)
#define PER(I, N) for (int I = (N); I >= 0; --I)
#define PERR(I, A, B) for (int I = (A); I >= B; --I)
#define ITR(I, A) for (__typeof((A).begin()) I=(A).begin(), _##i=(A).end(); I!=_##i; ++I)
#define RI(X) scanf("%d", &(X))
#define RII(X, Y) scanf("%d%d", &(X), &(Y))
#define RIII(X, Y, Z) scanf("%d%d%d", &(X), &(Y), &(Z))
#define DRI(X) int (X); scanf("%d", &X)
#define DRII(X, Y) int X, Y; scanf("%d%d", &X, &Y)
#define DRIII(X, Y, Z) int X, Y, Z; scanf("%d%d%d", &X, &Y, &Z)
#define RS(X) scanf("%s", (X))
#define CASET int ___T, case_n = 1; scanf("%d ", &___T); while (___T-- > 0)
#define MP make_pair
#define PB push_back
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)
#define PII pair<int,int>
#define VPII vector<pair<int,int> >
#define PLL pair<long long,long long>
#define F first
#define S second
#define LB(X) __builtin_ctz((X))
#define ONES(X) __builtin_popcount((X))
typedef long long LL;
using namespace std;
template <class T>  inline void smax(T &x,T y){ x = max((x), (y));}
template <class T>  inline void smin(T &x,T y){ x = min((x), (y));}
const int MOD = 1e9+7;
const int MOD2 = 1e9+9;
const int MOD3 = 1e9+21;
const int SIZE = 2*1e5+10;
const int INF = 0x3f3f3f3f;
const int MN = 300;
#define LOCALTEST 0 // change this to 1 to perform localtest on "in.txt"
int e,s,n,m;
vector<PII> v, V[4];
PII dp[SIZE];
PII go(int idx) {
    //printf("trying dp[%d]\n", idx);
    PII &ret = dp[idx];
    if (ret.F != -2) return ret;
    if (v[idx].F == e) return ret = MP(0, 0);
    if (v[idx+1].F > v[idx].F + s) return ret = MP(-1, -1);

    ret = MP(-1,-1);

    int pos = v[idx].F, x = v[idx].S;

    REPP(i,x,4) {
        vector<PII>::iterator it = lower_bound(ALL(V[i]), MP(pos+1,0));
        if (it != V[i].end() && v[it->S].F <= pos + s) {
            PII k = go(it->S);
            if (k.F >= 0) {
                int need = it->F - pos;
                if (x == 1) {
                    k.F += need;
                } else if (x == 2) {
                    k.S += need;
                }
            }
            if (ret.F < 0) ret = k;
            else if (ret.F > k.F) ret = k;
            else if (ret.F == k.F && ret.S > k.S) ret = k;
        }
    }
    PERR(i,x-1,1) {
        vector<PII>::iterator it = upper_bound(ALL(V[i]), MP(pos+s+1,-1));
        if (it == V[i].begin()) continue;
        it--;
        //printf("v[%d].F = %d\n", it->S, v[it->S].F);
        if (v[it->S].F > pos && v[it->S].F <= pos + s) {
            PII k = go(it->S);
            if (k.F >= 0) {
                int need = it->F - pos;
                if (x == 2) {
                    k.S += s;
                    k.F -= s - need;
                } else if (x == 3) {
                    if (i == 2) {
                        k.S -= s - need;
                    } else if (i == 1) {
                        k.F -= s - need;
                    }
                }
            }
            if (ret.F < 0) ret = k;
            else if (ret.F > k.F) ret = k;
            else if (ret.F == k.F && ret.S > k.S) ret = k;
        }
    }
    //printf("dp[%d] = %d %d\n", idx, ret.F, ret.S);
    return ret;
}
int main(){
    if (LOCALTEST) {
        freopen("in.txt", "r", stdin);
        freopen("out.txt", "w", stdout);
    }
    while (RII(e,s) == 2) {
        RII(n,m);
        v.clear();
        v.PB(MP(e,3));
        REP(i,n) {
            DRII(t,x);
            if (x >= e) continue;
            v.PB(MP(x,t));
        }
        sort(ALL(v));
        //REP(i,SZ(v)) printf("(%d,%d)%c",v[i].F,v[i].S,i==SZ(v)-1?'\n':' ');
        REP(i,4) V[i].clear();
        REP(i,SZ(v)) V[v[i].S].PB(MP(v[i].F, i));

        REP(i,SIZE) dp[i] = MP(-2,-2);

        REP(i,m) {
            DRI(st);
            if (st + s >= e) {
                printf("0 0\n");
                continue;
            }

            PII ret = MP(-1,-1);
            int pos = st, x = 3;
            REPP(i,x,4) {
                vector<PII>::iterator it = lower_bound(ALL(V[i]), MP(pos+1,0));
                if (it != V[i].end() && v[it->S].F <= pos + s) {
                    //if (it != V[i].end()) printf("iterator %d, v[%d].F = %d\n", it - V[i].begin(), it->S, v[it->S].F);
                    PII k = go(it->S);
                    if (k.F >= 0) {
                        int need = it->F - pos;
                        if (x == 1) {
                            k.F += need;
                        } else if (x == 2) {
                            k.S += need;
                        }
                    }
                    if (ret.F < 0) ret = k;
                    else if (ret.F > k.F) ret = k;
                    else if (ret.F == k.F && ret.S > k.S) ret = k;
                }
            }
            PERR(i,x-1,1) {
                vector<PII>::iterator it = upper_bound(ALL(V[i]), MP(pos+s+1,-1));
                if (it == V[i].begin()) continue;
                it--;
                if (v[it->S].F > pos && v[it->S].F <= pos + s) {
                    //printf("iterator %d, v[%d].F = %d\n", it - V[i].begin(), it->S, v[it->S].F);
                    PII k = go(it->S);
                    if (k.F >= 0) {
                        int need = it->F - pos;
                        if (x == 2) {
                            k.S += need;
                        } else if (x == 3) {
                            if (i == 2) {
                                k.S -= s - need;
                            } else if (i == 1) {
                                k.F -= s - need;
                            }
                        }
                    }
                    if (ret.F < 0) ret = k;
                    else if (ret.F > k.F) ret = k;
                    else if (ret.F == k.F && ret.S > k.S) ret = k;
                }
            }
            printf("%d %d\n", ret.F, ret.S);
        }
    }
    return 0;
}

// 0010011110
// answer 3


#include <bits/stdc++.h>
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define REP(I, N) for (int I = 0; I < (N); ++I)
#define REPP(I, A, B) for (int I = (A); I < (B); ++I)
#define PER(I, N) for (int I = (N); I >= 0; --I)
#define PERR(I, A, B) for (int I = (A); I >= B; --I)
#define ITR(I, A) for (__typeof((A).begin()) I=(A).begin(), _##i=(A).end(); I!=_##i; ++I)
#define RI(X) scanf("%d", &(X))
#define RII(X, Y) scanf("%d%d", &(X), &(Y))
#define RIII(X, Y, Z) scanf("%d%d%d", &(X), &(Y), &(Z))
#define DRI(X) int (X); scanf("%d", &X)
#define DRII(X, Y) int X, Y; scanf("%d%d", &X, &Y)
#define DRIII(X, Y, Z) int X, Y, Z; scanf("%d%d%d", &X, &Y, &Z)
#define RS(X) scanf("%s", (X))
#define CASET int ___T, case_n = 1; scanf("%d ", &___T); while (___T-- > 0)
#define MP make_pair
#define PB push_back
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)
#define PII pair<int,int>
#define VPII vector<pair<int,int> >
#define PLL pair<long long,long long>
#define F first
#define S second
#define LB(X) __builtin_ctz((X))
#define ONES(X) __builtin_popcount((X))
typedef long long LL;
using namespace std;
template <class T>  inline void smax(T &x,T y){ x = max((x), (y));}
template <class T>  inline void smin(T &x,T y){ x = min((x), (y));}
const int MOD = 1e9+7;
const int MOD2 = 1e9+9;
const int MOD3 = 1e9+21;
const int SIZE = 2*1e5+10;
const int INF = 0x3f3f3f3f;
const int MN = 300;
#define LOCALTEST 0 // change this to 1 to perform localtest on "in.txt"
int e,s,n,m;
vector<PII> v, V[4];
PII dp[SIZE];
PII go(int idx) {
    //printf("trying dp[%d]\n", idx);
    PII &ret = dp[idx];
    if (ret.F != -2) return ret;
    if (v[idx].F == e) return ret = MP(0, 0);
    if (v[idx+1].F > v[idx].F + s) return ret = MP(-1, -1);

    ret = MP(-1,-1);

    int pos = v[idx].F, x = v[idx].S;
    bool done = false;

    REPP(i,x,4) {
        vector<PII>::iterator it = lower_bound(ALL(V[i]), MP(pos+1,0));
        if (it != V[i].end() && v[it->S].F <= pos + s) {
            PII k = go(it->S);
            if (k.F >= 0) {
                int need = it->F - pos;
                if (x == 1) {
                    k.F += need;
                } else if (x == 2) {
                    k.S += need;
                }
            }
            if (ret.F < 0) ret = k;
            else if (ret.F > k.F) ret = k;
            done = true;
        }
    }
    PERR(i,x-1,1) {
        if (done) break;
        vector<PII>::iterator it = upper_bound(ALL(V[i]), MP(pos+s+1,-1));
        if (it == V[i].begin()) continue;
        it--;
        //printf("v[%d].F = %d\n", it->S, v[it->S].F);
        if (v[it->S].F > pos && v[it->S].F <= pos + s) {
            PII k = go(it->S);
            if (k.F >= 0) {
                int need = it->F - pos;
                if (x == 2) {
                    k.S += s;
                    k.F -= s - need;
                } else if (x == 3) {
                    if (i == 2) {
                        k.S -= s - need;
                    } else if (i == 1) {
                        k.F -= s - need;
                    }
                }
            }
            ret = k;
            done = true;
        }
    }
    //printf("dp[%d] = %d %d\n", idx, ret.F, ret.S);
    return ret;
}
int main(){
    if (LOCALTEST) {
        freopen("in.txt", "r", stdin);
        freopen("out.txt", "w", stdout);
    }
    while (RII(e,s) == 2) {
        RII(n,m);
        v.clear();
        v.PB(MP(e,3));
        REP(i,n) {
            DRII(t,x);
            if (x >= e) continue;
            v.PB(MP(x,t));
        }
        sort(ALL(v));
        //REP(i,SZ(v)) printf("(%d,%d)%c",v[i].F,v[i].S,i==SZ(v)-1?'\n':' ');
        REP(i,4) V[i].clear();
        REP(i,SZ(v)) V[v[i].S].PB(MP(v[i].F, i));

        REP(i,SIZE) dp[i] = MP(-2,-2);

        REP(i,m) {
            DRI(st);
            if (st + s >= e) {
                printf("0 0\n");
                continue;
            }

            PII ret = MP(-1,-1);
            int pos = st, x = 3;
            bool done = false;
            REPP(i,x,4) {
                vector<PII>::iterator it = lower_bound(ALL(V[i]), MP(pos+1,0));
                if (it != V[i].end() && v[it->S].F <= pos + s) {
                    //if (it != V[i].end()) printf("iterator %d, v[%d].F = %d\n", it - V[i].begin(), it->S, v[it->S].F);
                    PII k = go(it->S);
                    if (k.F >= 0) {
                        int need = it->F - pos;
                        if (x == 1) {
                            k.F += need;
                        } else if (x == 2) {
                            k.S += need;
                        }
                    }
                    if (ret.F < 0) ret = k;
                    else if (ret.F > k.F) ret = k;
                    done = true;
                }
            }
            PERR(i,x-1,1) {
                if (done) break;
                vector<PII>::iterator it = upper_bound(ALL(V[i]), MP(pos+s+1,-1));
                if (it == V[i].begin()) continue;
                it--;
                if (v[it->S].F > pos && v[it->S].F <= pos + s) {
                    //printf("iterator %d, v[%d].F = %d\n", it - V[i].begin(), it->S, v[it->S].F);
                    PII k = go(it->S);
                    if (k.F >= 0) {
                        int need = it->F - pos;
                        if (x == 2) {
                            k.S += need;
                        } else if (x == 3) {
                            if (i == 2) {
                                k.S -= s - need;
                            } else if (i == 1) {
                                k.F -= s - need;
                            }
                        }
                    }
                    ret = k;
                    done = true;
                }
            }
            printf("%d %d\n", ret.F, ret.S);
        }
    }
    return 0;
}

// 0010011110
// answer 3


#include <bits/stdc++.h>
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define REP(I, N) for (int I = 0; I < (N); ++I)
#define REPP(I, A, B) for (int I = (A); I < (B); ++I)
#define PER(I, N) for (int I = (N); I >= 0; --I)
#define PERR(I, A, B) for (int I = (A); I >= B; --I)
#define ITR(I, A) for (__typeof((A).begin()) I=(A).begin(), _##i=(A).end(); I!=_##i; ++I)
#define RI(X) scanf("%d", &(X))
#define RII(X, Y) scanf("%d%d", &(X), &(Y))
#define RIII(X, Y, Z) scanf("%d%d%d", &(X), &(Y), &(Z))
#define DRI(X) int (X); scanf("%d", &X)
#define DRII(X, Y) int X, Y; scanf("%d%d", &X, &Y)
#define DRIII(X, Y, Z) int X, Y, Z; scanf("%d%d%d", &X, &Y, &Z)
#define RS(X) scanf("%s", (X))
#define CASET int ___T, case_n = 1; scanf("%d ", &___T); while (___T-- > 0)
#define MP make_pair
#define PB push_back
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)
#define PII pair<int,int>
#define VPII vector<pair<int,int> >
#define PLL pair<long long,long long>
#define F first
#define S second
#define LB(X) __builtin_ctz((X))
#define ONES(X) __builtin_popcount((X))
typedef long long LL;
using namespace std;
template <class T>  inline void smax(T &x,T y){ x = max((x), (y));}
template <class T>  inline void smin(T &x,T y){ x = min((x), (y));}
const int MOD = 1e9+7;
const int MOD2 = 1e9+9;
const int MOD3 = 1e9+21;
const int SIZE = 1e5+10;
const int INF = 0x3f3f3f3f;
const int MN = 300;
#define LOCALTEST 0 // change this to 1 to perform localtest on "in.txt"
int e,s,n,m;
vector<PII> v, V[4];
PII dp[SIZE];
PII go(int idx) {
    //printf("trying dp[%d]\n", idx);
    PII &ret = dp[idx];
    if (ret.F != -2) return ret;
    if (v[idx].F == e) return ret = MP(0, 0);
    if (v[idx+1].F > v[idx].F + s) return ret = MP(-1, -1);

    ret = MP(-1,-1);

    int pos = v[idx].F, x = v[idx].S;
    bool done = false;
    REPP(i,x,4) {
        if (done) break;
        vector<PII>::iterator it = lower_bound(ALL(V[i]), MP(pos+1,0));
        if (it != V[i].end() && v[it->S].F <= pos + s) {
            PII k = go(it->S);
            if (k.F >= 0) {
                int need = it->F - pos;
                if (x == 1) {
                    k.F += need;
                } else if (x == 2) {
                    k.S += need;
                }
            }
            ret = k;
            done = true;
        }
    }
    PERR(i,x-1,1) {
        if (done) break;
        vector<PII>::iterator it = upper_bound(ALL(V[i]), MP(pos+s+1,-1));
        if (it == V[i].begin()) continue;
        it--;
        //printf("v[%d].F = %d\n", it->S, v[it->S].F);
        if (v[it->S].F > pos && v[it->S].F <= pos + s) {
            PII k = go(it->S);
            if (k.F >= 0) {
                int need = it->F - pos;
                if (x == 2) {
                    k.S += s;
                    k.F -= s - need;
                } else if (x == 3) {
                    if (i == 2) {
                        k.S -= s - need;
                    } else if (i == 1) {
                        k.F -= s - need;
                    }
                }
            }
            ret = k;
            done = true;
        }
    }
    //printf("dp[%d] = %d %d\n", idx, ret.F, ret.S);
    return ret;
}
int main(){
    if (LOCALTEST) {
        freopen("in.txt", "r", stdin);
        freopen("out.txt", "w", stdout);
    }
    while (RII(e,s) == 2) {
        RII(n,m);
        v.clear();
        v.PB(MP(e,3));
        REP(i,n) {
            DRII(t,x);
            if (x >= e) continue;
            v.PB(MP(x,t));
        }
        sort(ALL(v));
        //REP(i,SZ(v)) printf("(%d,%d)%c",v[i].F,v[i].S,i==SZ(v)-1?'\n':' ');
        REP(i,4) V[i].clear();
        REP(i,SZ(v)) V[v[i].S].PB(MP(v[i].F, i));

        REP(i,SIZE) dp[i] = MP(-2,-2);

        REP(i,m) {
            DRI(st);
            if (st + s >= e) {
                printf("0 0\n");
                continue;
            }

            PII ret = MP(-1,-1);
            int pos = st, x = 3;
            bool done = false;
            REPP(i,x,4) {
                if (done) break;
                vector<PII>::iterator it = lower_bound(ALL(V[i]), MP(pos+1,0));
                if (it != V[i].end() && v[it->S].F <= pos + s) {
                    //if (it != V[i].end()) printf("iterator %d, v[%d].F = %d\n", it - V[i].begin(), it->S, v[it->S].F);
                    PII k = go(it->S);
                    if (k.F >= 0) {
                        int need = it->F - pos;
                        if (x == 1) {
                            k.F += need;
                        } else if (x == 2) {
                            k.S += need;
                        }
                    }
                    ret = k;
                    done = true;
                }
            }
            PERR(i,x-1,1) {
                if (done) break;
                vector<PII>::iterator it = upper_bound(ALL(V[i]), MP(pos+s+1,-1));
                if (it == V[i].begin()) continue;
                it--;
                if (v[it->S].F >= pos && v[it->S].F <= pos + s) {
                    //printf("iterator %d, v[%d].F = %d\n", it - V[i].begin(), it->S, v[it->S].F);
                    PII k = go(it->S);
                    if (k.F >= 0) {
                        int need = it->F - pos;
                        if (x == 2) {
                            k.S += need;
                        } else if (x == 3) {
                            if (i == 2) {
                                k.S -= s - need;
                            } else if (i == 1) {
                                k.F -= s - need;
                            }
                        }
                    }
                    ret = k;
                    done = true;
                }
            }
            printf("%d %d\n", ret.F, ret.S);
        }
    }
    return 0;
}

// 0010011110
// answer 3