Pre - calculate prefix array
int prefix [ N ] [ 26 ] ; memset ( prefix , 0 , sizeof prefix ) ; preCalculate ( s , prefix ) ; int queries [ ] [ 2 ] = { { 1 , 4 } , { 3 , 4 } } ; int q = sizeof ( queries ) / sizeof ( queries [ 0 ] ) ;