x = input()
n = int(input())


def check(string,word):
    search_state = 0
    first_match = 0
    l = len(string)
    i = 0
    while (i < l):
        # print(string[i])
        if i+search_state < l and string[i+search_state] == word[search_state]:
            if first_match == 0:
                first_match = search_state
            search_state += 1
            if search_state == len(word):
                return 1
        else:
            i += max(min(first_match,search_state),1)
            search_state = 0
            
    return 0
            
# print(check(x,'baa'))
    
for i in range(n):
    y = input()
    print(i + check(x,y))
    
# for i in range(n):
#     y = input()
#     print(str(i) + y)
#     # if y in x:
    #     print(i + 1)
    # else:
    #     print(i + 0)
        
        
        
