아직 만들고 있는 페이지입니다.

이 페이지는 아직 만드는 중입니다. 보이는 내용은 바뀔 수 있습니다.

Earthquake

시간 제한3초메모리 제한1024 MB

요약
물음표와 별표로 가려진 9자리 전화번호마다, N개의 깨끗한 번호 중 패턴에 맞는 것이 몇 개인지 센다.
난이도

보통10점 중 6점

유형
문자열 매칭, 해시맵, 완전 탐색
정답자
아직 제출이 없습니다

문제

Cimrman has quite a number of collaborators. Tomorrow morning, he is planning to make phone calls to many of them and his assistant had prepared a list of phone numbers on a sheet of paper. Regrettably, an earthquake struck yesterday. The coffee and juice stored close to the list had spilled out and made stains on the list. Upon close examination of the affected list, the following turned out:

  • No digit affected by a stain is readable.
  • Each coffee stain covers exactly one digit in any of the numbers.
  • There are at most two coffee stains on any of the numbers.
  • Each juice stain covers one or more consecutive digits in any of the numbers.
  • There is at most one juice stain on any of the numbers.
  • No stain affects more than one number.
  • No number has been affected by coffee and juice simultaneously.

Fortunately, Cimrman has an older list of his collaborators phone numbers. This older list was stored in the drawer and it survived the earthquake undamaged. Now, it will help to restore the damaged list. First, the assistant needs to know, to how many items on the old list may correspond each of the items on the damaged list.

입력

The first input line contains one integer N (1 ≤ N ≤ 104), the number of phone numbers in the older undamaged list. Each of the next N lines contains one phone number consisting of exactly 9 digits, leading zeros are allowed. All numbers are mutually different. Next, there is a line with one integer Q (1 ≤ Q ≤ 3 · 105), the number of phone numbers on the damaged list. Each of the next Q lines contains one, possibly stained, phone number from the damaged list. A coffee stain is represented by a question mark (“?”), a juice stain is represented by an asterisk (“*”). There are no spaces in any numbers. The phone numbers are given in no specific order.

출력

Output Q lines, the i-th line should contain the number of items in the undamaged list which may correspond to the i-th item on the damaged list.

예제2

  1. 예제 1

    입력
    2
    728147956
    606327482
    2
    72814?956
    622629145
    
    예상 출력
    1
    0
    
  2. 예제 2

    입력
    4
    606200400
    606200500
    606300500
    706200400
    3
    ?06200400
    6*00
    606?00?00
    
    예상 출력
    2
    3
    3