import java.util.*; import java.io.*; //comment out when submitting public class p { Scanner in = new Scanner(System.in); // static Scanner in = null; public static void main(String[] args) { // //comment out this part // try { // File file = new File("input.txt"); // in = new Scanner(file); // } catch(FileNotFoundException e) { // System.out.println("error"); // } new p().go(); } private void go() { //read the input int n = Integer.parseInt(in.nextLine()); while(in.hasNextLine()) { String target = in.nextLine(); int count = 0; for(int i = 1; i < target.length(); i++) { count += countRepeatedSubString(target, i); } System.out.println(count); } } private int countRepeatedSubString(String s, int len) { int count = 0; HashMap map = new HashMap(); for(int i = 0; i < s.length() - len + 1; i++) { String key = s.substring(i, i+len); if(map.containsKey(key)){ if(map.get(key) == 1) { count++; map.put(key, -1); } } else { map.put(key, 1); } } return count; } }