import java.io.*; import java.util.*; import java.text.*; import java.math.*; import java.util.regex.*; public class Solution { public static void main(String[] args) { Scanner in = new Scanner(System.in); String s = in.next(); int counter=0; int q = in.nextInt(); for(int a0 = 0; a0 < q; a0++){ int l = in.nextInt(); int r = in.nextInt(); String sub = s.substring(l,r); if(sub.equalsIgnoreCase(new StringBuilder(sub).reverse().toString())) { counter++; } } System.out.println(counter); } }