Ayu loves distinct letter sequences ,a distinct letter sequence is defined by a sequence of small case english alphabets such that no character appears more then once.
But however there are two phrases that she doesn't like these phrases are "kar" and "shi" and she is given a sequence of distinct characters and she wonders how many such sequences she can form using all the characters such that these phrases don't occur.
Help her finding the number of such sequences.
New Year Gift - It is guaranteed that for sequences of length greater then 6 letters k,a,r,s,h,i will be present(we thought of being generous, thank us later :)).

-----Input:-----
- First line will contain $T$, number of testcases. Then the testcases follow. 
- Each line consists of a string $S$ (3<=s.length<=18) of distinct characters.

-----Output:-----
Print the number of sequences that can be formed by permuting all the characters such that phrases "kar" and "shi" don't occur.

-----Constraints-----
- $1 \leq T \leq 10$
- $3 \leq S.length \leq 18$

-----Sample Input:-----
2
karp
abcd

-----Sample Output:-----
22
24

```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 = "# cook your dish here\r\nfrom collections import deque, defaultdict\r\nfrom math import sqrt, ceil,factorial\r\nimport sys\r\nimport copy\r\ndef get_array(): return list(map(int, sys.stdin.readline().strip().split()))\r\ndef get_ints(): return map(int, sys.stdin.readline().strip().split())\r\ndef input(): return sys.stdin.readline().strip()\r\n\r\nfor _ in range(int(input())):\r\n\r\n    s=input()\r\n    if len(s)>6:\r\n        ans=0\r\n        rem=len(s)-6\r\n        ans+=factorial(len(s))\r\n        ans-=2*(factorial(len(s)-2))\r\n        ans+=factorial(rem+2)\r\n        print(ans)\r\n\r\n    else:\r\n        if 'k' in s and 'r' in s and 'a' in s and 's' in s and 'h' in s and 'i' in s:\r\n            ans = 0\r\n            rem = len(s) - 6\r\n            ans += factorial(len(s))\r\n            ans -= 2 * (factorial(len(s) - 2))\r\n            ans += factorial(rem + 2)\r\n            print(ans)\r\n        else:\r\n            if 'k' in s and 'a' in s and 'r' in s:\r\n                ans=0\r\n                rem=len(s)-3\r\n                ans+=factorial(len(s))\r\n                ans-=factorial(rem+1)\r\n                print(ans)\r\n                continue\r\n            if 's' in s and 'h' in s and 'i' in s:\r\n                ans = 0\r\n                rem = len(s) - 3\r\n                ans += factorial(len(s))\r\n                ans -= factorial(rem + 1)\r\n                print(ans)\r\n                continue\r\n\r\n            print(factorial(len(s)))\r\n\r\n"
_co = compile(_CODE, USER_FILENAME, "exec")
exec(_co, ns, ns)

```

Measured memory_bytes: 178684