FINGP - Fingerprints

Professor Emad Eldin one of the best people in pattern recognition, he asked his students to create a program to check if a special pattern belongs to fingerprints of someone or not.

He said that we can consider that a computer reads the special pattern and the fingerprints as strings, and we can say that the special pattern belongs to the fingerprint if the last substring of the fingerprint string is the same as the special pattern string.

Your task is to help professor Emad students.

Input

The first line of the input contains special pattern string S (1 ≤ |S| ≤ 50). Second line will be a single integer N, the number of fingerprints (1 ≤ N ≤ 10). N lines follow, each line contains fingerprint string F (1 ≤ |F| ≤ 50).

Output

For each test case, print an integer K, the number of fingerprints strings that special pattern string belongs to it. Followed by K lines, each contains the fingerprint string that the special pattern string belongs to it. You should print the fingerprint strings in a lexicographical order. If there is no fingerprint belongs to the special pattern, print "Wrong fingerprints!" instead.

Examples

Input:
On
5
Pattern recognatiOn
CommOn patterN
game
organizatiOn
lion

Output:
2
Pattern recognatiOn
organizatiOn
Input:
Ze
2
Fingerprint
pattern design

Output:
Wrong fingerprints!

Notes

  • String S contains uppercase English letters ('A' - 'Z') and lowercase English letters ('a' - 'z') only.
  • All other strings in the input contains uppercase English letters ('A' - 'Z'), lowercase English letters ('a' - 'z') and spaces (' ') only.
  • All strings are case sensitive ('A' is not equal to 'a').
  • Lexicographical order is defined in following way. When we compare s and t, first we find the leftmost position with differing characters: si ≠ ti. If there is no such position (i.e. s is a prefix of t or vice versa) the shortest string is less. Otherwise, we compare characters si and ti according to their order in alphabet.

Added by:atef
Date:2015-04-24
Time limit:1s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All except: MAWK BC C-CLANG NCSHARP CPP14-CLANG COFFEE D-CLANG D-DMD DART ELIXIR FANTOM FORTH JULIA KTLN NIM OBJC OBJC-CLANG OCT PICO PROLOG PYPY3 R RACKET RUST CHICKEN SQLITE SWIFT UNLAMBDA

hide comments
2015-06-20 11:04:24 atef
@Harshad Gupta
abc
5
abc
abc
abc abc
eabc abc abc
abc cba

this test case should out put
3 only your could output 4 :)
care the first finger have space
abc_ it not abc :) have fun man
2015-06-16 21:22:28 Nick
This question sucks.

Last edit: 2015-06-16 21:24:26
2015-06-08 19:58:58 Harshad Gupta
I think my solution is correct.... can u check it plzz. @atef

Last edit: 2015-06-09 18:15:37
2015-06-06 16:57:22 atef
@rishabhtwr07
it should output
1
abc mohib
i saw your code and you need to try this test case
abc
5
abc
abc
abc abc
eabc abc abc
abc cba

care abc -- have space after c

Last edit: 2015-06-06 16:58:15
2015-05-30 21:24:37 rishabhtwr07
@:.Mohib.::
note there are blank spaces after each fingerprint string.
the test case is ->
mohib
2
mohib_
abc_mohib_

here '_' denotes blank space.
how come there are two valid fingerprints ?
2015-05-30 10:07:12 :.Mohib.:
@rishabhtwr07 answer would be...
2
abc mohib
mohib
2015-05-30 06:08:26 rishabhtwr07
@atef
what is the output for.
mohib
2
mohib
abc mohib
2015-05-27 13:16:18 :.Mohib.:
AC now... Thnx for ur help @atef :)
2015-05-25 10:23:41 atef
mani_mackinnon both accepted :)
2015-05-25 10:18:26 atef
:.Mohib.:: try this :)
mohib
2
mohib
abc mohib
© Spoj.com. All Rights Reserved. Spoj uses Sphere Engine™ © by Sphere Research Labs.