#include<iostream>
using namespace std;
const int MAXN=5e5;

extern void start (char []);
extern int round (int, int);

char w_gr[MAXN];
int main () {
    cin >> w_gr ;
    start(w_gr);
    int q;
    cin >> q ;
    for (int i=1; i<=q; i++) {
        int m,k;
        cin >> m >> k ;
        cout << round(m,k) << endl ;
    }
    return 0;
}
