#include <fstream>
#include <string>
#include <sstream>
#include <cmath>
#define MAX_N 1500
using namespace std;
int main(){
fstream in("dcball.in", ios::in), out("dcball.out", ios::out);
int n, l, balls[MAX_N][2], m;
in >> n >> l;
for(int i = 0; i < n; ++i)
in >> balls[i][0] >> balls[i][1];
in >> m;
for(int i = 0; i < m; ++i){
int t;
in >> t;
for(int j = 0; j < n; ++j){
int pos = balls[j][0];
if(balls[j][1] == 1) pos -= t;
else pos += t;
if(pos <= 0 || pos >= l) out << "fire in the hole" << " ";
else out << pos << " ";
}
out << endl;
}
return 0;
}