Nobody outside the cooking community knows that Chef is a big fan of Chefgram™ — a social network where chefs and cooks upload their secret kitchen photos.
Recently Chef clicked a beautiful photo, which is represented using 10 pixels in a single row. Respecting Chefgram™'s boolean roots, every pixel is either white or black.

Chefgram™ has N filters. Every filter is a string containing 10 symbols. Every symbol is either '+' or '-'.

- A '+' at the ith position in a filter means that if Chef applies this filter to his photo, the ith pixel will be inverted: it becomes black if it was originally white, and vice versa. 
- A '-' at the ith position in a filter string means that if Chef applies this filter to his photo, the ith pixel will remain unchanged.

Chef can apply as many filters as he wants from a list. He can pick any subset of filters and consequently apply them to a photo.

For example:

- Imagine that Chef has a photo "bbwwbbwwbb" (where 'b' stands for black and 'w' stands for white).
- He applies filters "++--++--++", "-+-+-+-+-+".
- Applying the first filter will transform his picture to "wwwwwwwwww". 
- Applying the second filter on the transformed picture will give Chef the picture "wbwbwbwbwb".

Even if Chefgram™ has two or more identical filters, they are still considered different!

Chef is extremely interested in knowing how many different subsets of all the Chefgram™ filters can he apply to transform his photo into 10 black pixels?

-----Input-----
- The first line of input contains a single integer T — the number of test cases.
- First line of each test case contains a string S. Each symbol is either 'b' or 'w'. This is Chef's photo.
- Second line of each test case contains a single integer N — the number of Chefgram™ filters.
- Each of the next N lines contains a single string Fi, each symbol of which is either '+' or '-'. This string is the ith Chefgram™ filter.

-----Output-----
- For each test case, output a single line containing a single integer — answer to Chef's question modulo 109+7.

-----Constraints-----
- 1 ≤ T ≤ 5
- |S| = 10
- 1 ≤ N ≤ 10^5
- |Fi| = 10

-----Subtasks-----
- Subtask 1: T ≤ 5; N ≤ 20; Points: 20
- Subtask 2: T ≤ 5; N ≤ 10^3; Points: 30
- Subtask 3: T ≤ 5; N ≤ 10^5; Points: 50

-----Example-----
Input:
3
wwwwwwwwww
3
+-+-+-+-+-
----------
+---------
wbwbwbwbwb
3
+-+-+-+-+-
+-+-------
----+-+-+-
bbbbbbbbbb
2
----------
----------

Output:
0
2
4

-----Explanation-----
Example case 1. There is no filter or combination of filters transforming the picture to whole black. 
Example case 2. Chef can either apply the first filter (and invert all whites) or apply the second and third filters in any order.
Example case 3. Picture is already fully black, and we have two different identity filters. Chef can either apply the empty subset of filters, the first filter only, the second filter only, or both.

```python

USER_FILENAME = "<user_code>"
import sys, json, builtins
import math, heapq, bisect, itertools, functools, collections, statistics, fractions, decimal, operator, array, random, re, string, os, pathlib
try:
    import resource as _res
except Exception:
    _res = None
from collections import Counter, defaultdict, deque, OrderedDict
from functools import lru_cache, reduce
from itertools import accumulate, permutations, combinations, product
from math import gcd, ceil, floor, sqrt
from decimal import Decimal
try:
    from typing import *
except Exception:
    pass
try:
    sys.setrecursionlimit(1_000_000)
except Exception:
    pass
try:
    import site as _site
    try:
        _sys_sites = _site.getsitepackages() if hasattr(_site, "getsitepackages") else []
        for _p in _sys_sites:
            if _p and _p not in sys.path:
                sys.path.append(_p)
    except Exception:
        pass
    try:
        _usp = _site.getusersitepackages()
        if isinstance(_usp, str):
            _usp = [_usp]
        for _p in _usp:
            if _p and _p not in sys.path:
                sys.path.append(_p)
    except Exception:
        pass
except Exception:
    pass

ns = {"__name__": "__main__"}
for _k, _v in list(globals().items()):
    if not _k.startswith("_"):
        ns[_k] = _v
_CODE = 'import itertools\nimport numpy as np\nb = np.zeros((100001), dtype=np.int)\ndef power2(a):\n\tb[0] = 1\n\tif b[a] > 0:\n\t\treturn b[a]\n\telse:\n\t\tfor i in range(1,a+1):\n\n\t\t\tb[i] = b[i-1]*2\n\t\t\tif b[i] > (10**9+7):\n\t\t\t\tb[i] = b[i]%(10**9+7)\n\t\treturn b[a]\n\n\ndef __starting_point():\n\tt = eval(input())\n\tfor i in range(t):\n\t\ts = input()\n\t\tn = eval(input())\n\t\tf_list = []\n\t\tcount = 0\n\t\tfor j in range(n):\n\t\t\tf_list.append(input())\n\t\tinp = ""\n\t\tbin_list = []\n\t\tfor j in range(len(s)):\n\t\t\tif s[j] == \'w\':\n\t\t\t\tinp = inp + \'0\'\n\t\t\telse:\n\t\t\t\tinp = inp + \'1\'\n\t\t#print inp\n\n\t\ta = np.zeros((1024), dtype=np.int)\n\t\tfor j in range(n):\n\t\t\ts1 = ""\n\t\t\tfor k in range(len(f_list[j])):\n\t\t\t\tif f_list[j][k]==\'+\':\n\t\t\t\t\ts1 = s1 + \'1\'\n\t\t\t\telse:\n\t\t\t\t\ts1 = s1 + \'0\'\n\t\t\tif n < 1024:\n\t\t\t\tbin_list.append(s1)\n\t\t\tp = int(s1,2)\n\t\t\tif a[p] == 0:\n\t\t\t\tcount = count+1\n\t\t\ta[p] = a[p]+1\n\t\tcount_2 = 0\n\n\n\t\t#print a\n\t\t\t\n\t\tif n < 1024:\n\t\t\tdp = np.zeros((n+1,1024) ,dtype=np.int64)\n\t\t\tdp[0,0] = 1\n\t\t\tfor j in range(1,n+1):\n\t\t\t\tfor k in range(1024):\n\t\t\t\t#print j-1\n\t\t\t\t#print k^int(bin_list[j-1],2)\n\n\t\t\t\t\tdp[j,k] = (dp[j-1][k] + dp[j-1][k^int(bin_list[j-1],2)])%(10**9+7)\n\n\t\t\t\t#print dp\n\t\t\tp = 1023 ^ int(inp,2)\n\n\t\t\tprint(dp[n,p]%(10**9+7))\n\n\t\telse:\n\n\t\t\tdp = np.zeros((1025,1024) ,dtype=np.int64)\n\t\t\tdp[0,0] = 1\n\t\t\tfor j in range(1,1025):\n\t\t\t\tcount_2 = count_2 + 1\n\t\t\t\tif a[j-1] > 0:\n\t\t\t\t\tl = power2(a[j-1]-1)\n\t\t\t\tfor k in range(1024):\n\t\t\t\t#print j-1\n\t\t\t\t#print k^int(bin_list[j-1],2)\n\t\t\t\t\tif a[j-1] > 0:\n\t\t\t\t\t\tdp[j,k] = (((dp[j-1][k] + dp[j-1][k^(j-1)])%(10**9+7)) * l )%(10**9+7)\n\t\t\t\t\telif dp[j-1][k] > 0:\n\t\t\t\t\t\tdp[j,k] = dp[j-1][k]\n\n\t\t\t\tif count_2 == count:\n\t\t\t\t\tbreak\n\t\t\t\t#print dp\n\t\t\tp = 1023 ^ int(inp,2)\n\n\t\t\tprint(dp[j,p]%(10**9+7))\n\n\n\n\n\n\n\n\n\n__starting_point()'
_co = compile(_CODE, USER_FILENAME, "exec")
exec(_co, ns, ns)

```

Measured memory_bytes: