Under construction

Still being built. Things may change

Mõttemeister

Interview

Time limit1sMemory limit1024 MB

Summary
Given a secret four-digit number and N guesses, print for each guess the count of correct digits (A) and the count of digits in the correct position (B).
Level

Easy3 of 10

Topics
Implementation, Array, Hash map, Brute force
Solved
No attempts yet

Problem

Mõttemeister is a board game for two players. The first player thinks of a secret four-digit number, and the second player tries to guess it.

On each turn the guesser proposes a four-digit number. The first player replies with two numbers AA and BB: AA is how many of the digits in the proposed number are correct, and BB is how many of those are also in the correct position.

The guesser then makes a new proposal, and the game continues until the guesser finds the secret number or the number of turns exceeds a set limit.

For example, suppose the secret number is 5247. For the guess 1234 the reply is A=2A = 2 (the digits 2 and 4 are correct) and B=1B = 1 (the digit 2 is in the correct place).

If the proposed number contains repeated digits, each digit is counted as correct only as many times as it appears in the secret number.

Write a program that, given the secret number and a proposed number, finds the correct reply.

Input

The first line contains the secret four-digit number. The second line contains an integer NN (1≤N≤100001 \le N \le 10000). Each of the next NN lines contains one proposed four-digit number. Every number consists of exactly four digits and may have leading zeros.

Output

Print NN lines. Each line contains two integers AA and BB, where AA (0≤A≤40 \le A \le 4) is the number of correct digits in the corresponding proposal and BB (0≤B≤A0 \le B \le A) is how many of them are in the correct position.

Examples2

  1. Example 1

    Input
    5247
    1
    1234
    
    Expected output
    2 1
    
  2. Example 2

    Input
    2222
    3
    1234
    1111
    2222
    
    Expected output
    1 1
    0 0
    4 4