import java.util.*;
public class Substr {
public boolean[] chkSubStr(String[] p, int n, String s) {
// write code here
Node root = new Node();
for(int i=0;i<s.length();i++)
insert(root,s.substring(i));
boolean[] res = new boolean[n];
for(int i=0;i<n;i++){
res[i] = search(root,p[i]);
}
return res;
}
boolean search(Node root,String str){
for(int i=0;i<str.length();i++){
char ch = str.charAt(i);
if(root.child[ch-'a']==null) return false;
root = root.child[ch-'a'];
}
boolean flag = false;
for(int i=0;i<26;i++)
if(root.child[i]!=null)
flag = true;
return root.isWord || flag;
}
void insert(Node root, String str){
for(int i=0;i<str.length();i++){
char ch = str.charAt(i);
if(root.child[ch-'a']==null)
root.child[ch-'a'] = new Node();
root = root.child[ch-'a'];
}
root.isWord = true;
}
class Node{
public Node[] child = new Node[26];
boolean isWord;
Node(){
for(int i=0;i<26;i++)
child[i] = null;
this.isWord = false;
}
}
}