import java.io.*; import java.util.*; import java.text.*; import java.math.*; import java.util.regex.*; public class Solution { public static char inc(char x) { if(x=='z') { x='a'; } else { x=(char)((int)x+1); } return x; } static boolean pall(String org) { int length = org.length(); boolean ret=false; String reverse=""; if(length>=2) { for ( int i = length - 1; i >= 0; i-- ) reverse = reverse + org.charAt(i); if (org.equals(reverse)) ret= true; } else if(length==1) { ret=true; } // System.out.println("Entered string is a palindrome."); return ret; } public static Set permutationFinder(String str) { Set perm = new HashSet(); //Handling error scenarios if (str == null) { return null; } else if (str.length() == 0) { perm.add(""); return perm; } char initial = str.charAt(0); // first character String rem = str.substring(1); // Full string without first character Set words = permutationFinder(rem); for (String strNew : words) { for (int i = 0;i<=strNew.length();i++){ perm.add(charInsert(strNew, initial, i)); } } return perm; } public static String charInsert(String str, char c, int j) { String begin = str.substring(0, j); String end = str.substring(j); return begin + c + end; } static ArrayList> list; static void printSubsets(char set[]) { int n = set.length; list=new ArrayList>(); // Run a loop for printing all 2^n // subsets one by obe int count=0; for (int i = 0; i < (1< a1=new ArrayList(); // Print current subset for (int j = 0; j < n; j++){ // (1< 0) { //System.out.print(set[j] + " "); a1.add(set[j]); } } int len=a1.size(); char[] ch=new char[len]; for(int u=0;u s3=permutationFinder(st); Iterator it1= s3.iterator(); while(it1.hasNext()) { String sq=it1.next(); if(pall(sq)) { count+=1; break; } } } //System.out.println("}"); } System.out.println(count); } public static void main(String[] args) throws Exception{ //Scanner in = new Scanner(System.in); BufferedReader ip=new BufferedReader(new InputStreamReader(System.in)); String line=ip.readLine(); String[] ars=line.split("\\s+"); int n = Integer.parseInt(ars[0]); int q = Integer.parseInt(ars[1]); String s1 = ip.readLine(); int[] a1; for(int a0 = 0; a0 < q; a0++){ // your code goes here String s = ip.readLine(); //System.out.println(s); String[] ar=s.split("\\s+"); a1=new int[ar.length]; for(int i=0;i