# include <bits/stdc++.h>
using namespace std;
const int maxn= 2e5 + 10 ;
struct SuffixArray {
int r[ maxn] ;
int sa[ maxn] , rank[ maxn] , height[ maxn] ;
int t[ maxn] , t2[ maxn] , c[ maxn] , n;
int m;
void init ( char * s) {
n= strlen ( s) ;
for ( int i= 0 ; i< n; i++ ) r[ i] = int ( s[ i] ) ;
m= 128 ;
}
int cmp ( int * r, int a, int b, int l) {
return r[ a] == r[ b] && r[ a+ l] == r[ b+ l] ;
}
void build_sa ( ) {
int i, k, p, * x= t, * y= t2;
r[ n++ ] = 0 ;
for ( i= 0 ; i< m; i++ ) c[ i] = 0 ;
for ( i= 0 ; i< n; i++ ) c[ x[ i] = r[ i] ] ++ ;
for ( i= 1 ; i< m; i++ ) c[ i] += c[ i- 1 ] ;
for ( i= n- 1 ; i>= 0 ; i-- ) sa[ -- c[ x[ i] ] ] = i;
for ( k= 1 , p= 1 ; k< n; k*= 2 , m= p) {
for ( p= 0 , i= n- k; i< n; i++ ) y[ p++ ] = i;
for ( i= 0 ; i< n; i++ ) if ( sa[ i] >= k) y[ p++ ] = sa[ i] - k;
for ( i= 0 ; i< m; i++ ) c[ i] = 0 ;
for ( i= 0 ; i< n; i++ ) c[ x[ y[ i] ] ] ++ ;
for ( i= 1 ; i< m; i++ ) c[ i] += c[ i- 1 ] ;
for ( i= n- 1 ; i>= 0 ; i-- ) sa[ -- c[ x[ y[ i] ] ] ] = y[ i] ;
swap ( x, y) ;
p= 1 ;
x[ sa[ 0 ] ] = 0 ;
for ( i= 1 ; i< n; i++ ) x[ sa[ i] ] = cmp ( y, sa[ i- 1 ] , sa[ i] , k) ? p- 1 : p++ ;
}
n-- ;
}
void getHeight ( ) {
int i, j, k= 0 ;
for ( i= 1 ; i<= n; i++ ) rank[ sa[ i] ] = i;
for ( i= 0 ; i< n; i++ ) {
if ( k) k-- ;
j= sa[ rank[ i] - 1 ] ;
while ( r[ i+ k] == r[ j+ k] ) k++ ;
height[ rank[ i] ] = k;
}
}
int d[ maxn] [ 20 ] ;
void RMQ_init ( int A[ ] , int n) {
for ( int i= 1 ; i<= n; i++ ) d[ i] [ 0 ] = A[ i] ;
for ( int j= 1 ; ( 1 << j) <= n; j++ )
for ( int i= 1 ; i+ j- 1 <= n; i++ )
d[ i] [ j] = min ( d[ i] [ j- 1 ] , d[ i+ ( 1 << ( j- 1 ) ) ] [ j- 1 ] ) ;
}
int RMQ ( int L, int R) {
int k= 0 ;
while ( ( 1 << ( k+ 1 ) ) <= R- L+ 1 ) k++ ;
return min ( d[ L] [ k] , d[ R- ( 1 << k) + 1 ] [ k] ) ;
}
void LCP_init ( ) {
RMQ_init ( height, n) ;
}
int lcp ( int i, int j) {
if ( rank[ i] > rank[ j] ) swap ( i, j) ;
if ( rank[ i] == rank[ j] )
return n- i;
return RMQ ( rank[ i] + 1 , rank[ j] ) ;
}
void call_fun ( char * s) {
init ( s) ;
build_sa ( ) ;
getHeight ( ) ;
LCP_init ( ) ;
}
int LCS ( char * s1, char * s2) {
int p, ans;
int l= strlen ( s1) ;
p= l;
s1[ l] = '$' ;
s1[ l+ 1 ] = '\0' ;
strcat ( s1, s2) ;
call_fun ( s1) ;
ans= 0 ;
for ( int i= 2 ; i<= n; i++ )
if ( ( sa[ i- 1 ] < p&& sa[ i] > p) || ( sa[ i- 1 ] > p&& sa[ i] < p) ) ans= max ( ans, height[ i] ) ;
return ans;
}
} solver;
char s[ maxn] ;
int main ( ) {
while ( cin>> s) {
solver. call_fun ( s) ;
int q; scanf ( "%d" , & q) ;
long long ans1= 0 , ans2= 0 ;
int prel, prer;
for ( int i= 0 ; i< q; i++ ) {
int l, r; scanf ( "%d%d" , & l, & r) ;
ans1+= r- l+ 1 ;
if ( i== 0 ) {
ans2+= r- l+ 3 ;
prer= r; prel= l;
continue ;
}
int ans= min ( solver. lcp ( l, prel) , min ( r- l, prer- prel) ) ;
ans2+= ( int ) log10 ( ans? ans: 1 ) + 1 + r- l- ans+ 2 ;
prel= l; prer= r;
}
cout<< ans1<< " " << ans2<< endl;
}
}