#include <algorithm>
#include<cstdio>
#include<cstring>
#include<iostream>
using namespace std;
#define M 100010
int wa[M], wb[M], WS[M], wv[M];
int rk[M], sa[M], height[M];
int RMQ[21][M], mp[M], vis[M];
char s[M];
int a[M];
#define LL long long
LL sum[M];

int min(int x, int y)
{
    return x < y? x: y;
}

bool cmp(int *r, int i, int j, int len)
{
    return r[i] == r[j] && r[i+len] == r[j+len];
}

void suffix(int *r, int n, int m)
{
    int *x = wa, *y = wb, *t;
    int i, j, p;
    for(i = 0; i < m; i++) WS[i] = 0;
    for(i = 0; i < n; i++) WS[x[i] = r[i]]++;
    for(i = 1; i < m; i++) WS[i] += WS[i-1];
    for(i = n - 1; i >= 0; i--) sa[--WS[x[i]]] = i;

    for(j = 1, p = 0; p < n; j <<= 1, m = p){
        p = 0;
        for(i = n-j; i < n; i++) y[p++] = i;
        for(i = 0; i < n; i++) if(sa[i] >= j) y[p++] = sa[i] - j;
        for(i = 0; i < m; i++) WS[i] = 0;
        for(i = 0; i < n; i++) WS[wv[i] = x[y[i]]]++;
        for(i = 1; i < m; i++) WS[i] += WS[i-1];
        for(i = n-1; i >= 0; i--) sa[--WS[wv[i]]] = y[i];

        t = x; x = y; y = t; x[sa[0]] = 0;
        for(i = 1, p = 1; i < n; i++)
            x[sa[i]] = cmp(y, sa[i], sa[i-1], j) ? p - 1: p++;
    }
}

void setHeight(int *r, int n)
{
    int i, j, k;
    for(i = 0; i <= n; i++)
        rk[sa[i]] = i;
    for(i=0, k=0; i < n; height[rk[i++]] = k)
        for(k = k?k-1: 0, j = sa[rk[i]-1]; r[i+k] == r[j+k]; k++);
}

int minv[21][M];

void setRMQ(int n)
{
    mp[0] = -1;
    int i, j, a, b, x, y;
    for(i = 1; i <= n; i++)
        if((i&(i-1)) == 0) mp[i] = mp[i-1] + 1;
        else mp[i] = mp[i-1];
    for(i = 0; i <= n; i++) RMQ[0][i] = height[i], minv[0][i] = sa[i];
    for(j = 1; j <= mp[n]; j++)
        for(i = 0; i+(1<<j)-1<=n; i++){
            a = RMQ[j-1][i]; x = minv[j-1][i];
            b = RMQ[j-1][i+(1<<(j-1))]; y = minv[j-1][i+(1<<(j-1))];
            RMQ[j][i] = min(a, b);
            minv[j][i] = min( x, y );
        }
}

int find(int a, int b)
{
    if( a > b ) swap( a, b );
    if( a == b ) return M;
    ++a;
    int j = mp[b-a+1];
    int x = RMQ[j][a];
     b -= (1<<j) - 1;
    int y = RMQ[j][b];
    return min(x, y);
}
int fMin( int a, int b )
{
    int j = mp[ b - a + 1 ];
    int x = minv[j][a];
    b -= ( 1 << j ) - 1;
    int y = minv[j][b];
    return min( x, y );
}

void init( int n )
{
    sum[0] = 0;
    for( int i = 1; i <= n; ++i ){
        sum[i] = n - sa[i] - height[i];
        sum[i] += sum[i-1];
    }
}

int l, r;
void cal( LL k, int n )
{
    if( k > sum[n] ){
        l = 0, r = 0;
        return;
    }
    int x, y, mid;
    int i = lower_bound( sum, sum + 1 + n, k ) - sum;
    l = sa[i];
    x = sum[i] - sum[i-1];
    r = l + height[i] + x - 1;
    //++l, ++r;
    x = 0, y = i, mid;
    while( y > x ){
        mid = ( x + y ) >> 1;
        if( find( mid, i ) >= r - l + 1 ) y = mid;
        else x = mid + 1;
    }
    int ll = x;
    x = i, y = n;
    while( y > x ){
        mid = ( x + y + 1 ) >> 1;
        if( find( i, mid ) >= r - l + 1 ) x = mid;
        else y = mid - 1;
    }
    int rr = y;
    
    x = fMin( ll, rr );
    y = x + r - l;

    l = x, r = y;
    ++l, ++r;
}
int main()
{
    int n, m, len;
    LL k;
    while( scanf( "%s", s ) == 1 ){
        int n = strlen( s );
        for( int i = 0; i < n; ++i ) a[i] = s[i] - 'a' + 1;
        a[n] = 0;
        suffix( a, n + 1, 30 );
        setHeight( a, n );
        setRMQ( n );
        init( n );
        scanf( "%d", &m );
        l = r = 0;
        while( m-- ){
            scanf( "%lld", &k );
            k = ( k ^ l ^ r ) + 1;
            cal( k, n );
            printf( "%d %d\n", l, r );
        }
    }
}