Problem: We'll call string s[a, b] = sasa + 1... sb (1 ≤ a ≤ b ≤ |s|) a substring of string s = s1s2... s|s|, where |s| is the length of string s.

The trace of a non-empty string t is a set of characters that the string consists of. For example, the trace of string "aab" equals {'a', 'b'}.

Let's consider an arbitrary string s and the set of its substrings with trace equal to C. We will denote the number of substrings from this set that are maximal by inclusion by r(C, s). Substring s[a, b] of length n = b - a + 1 belonging to some set is called maximal by inclusion, if there is no substring s[x, y] in this set with length greater than n, such that 1 ≤ x ≤ a ≤ b ≤ y ≤ |s|. Two substrings of string s are considered different even if they are equal but they are located at different positions of s.

Polycarpus got a challenging practical task on a stringology exam. He must do the following: given string s and non-empty sets of characters C1, C2, ..., Cm, find r(Ci, s) for each set Ci. Help Polycarpus to solve the problem as he really doesn't want to be expelled from the university and go to the army!

Input

The first line contains a non-empty string s (1 ≤ |s| ≤ 106).

The second line contains a single integer m (1 ≤ m ≤ 104). Next m lines contain descriptions of sets Ci. The i-th line contains string ci such that its trace equals Ci. It is guaranteed that all characters of each string ci are different.

Note that Ci are not necessarily different. All given strings consist of lowercase English letters.

Output

Print m integers — the i-th integer must equal r(Ci, s).

Examples

Input

aaaaa
2
a
a


Output

1
1


Input

abacaba
3
ac
ba
a


Output

1
2
4

Solution (in CPP):

Solution:
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:66777216")
using namespace std;
const int mod = 32771;
struct HashMap {
  int last[mod + 1];
  int nx[mod + 1], key[mod + 1], val[mod + 1], hc;
  inline void reset() {
    hc = 0;
    memset(last, -1, sizeof(last));
  }
  inline void cr(int k) {
    int h = k % mod;
    for (int w = last[h]; w >= 0; w = nx[w]) {
      if (key[w] == k) return;
    }
    key[hc] = k;
    val[hc] = 0;
    nx[hc] = last[h];
    last[h] = hc++;
  }
  inline void add(int v, int vv) {
    for (int w = last[v % mod]; w >= 0; w = nx[w]) {
      if (key[w] == v) {
        val[w] += vv;
        return;
      }
    }
  }
  inline int fnd(int v) {
    for (int w = last[v % mod]; w >= 0; w = nx[w]) {
      if (key[w] == v) return val[w];
    }
    return 0;
  }
};
int a, b, c, d, i, j, n, m, k;
int quer[10002];
char str[1000002], tmp[33];
int nx[26], ind[26];
struct cmp {
  bool operator()(const int &a, const int &b) const { return nx[a] < nx[b]; }
};
HashMap q;
int main() {
  q.reset();
  scanf("%s", str);
  n = (int)strlen(str);
  scanf("%d", &m);
  for (int _n((m)-1), i(0); i <= _n; i++) {
    scanf("%s", tmp);
    b = (int)strlen(tmp);
    int cmask = 0;
    for (int _n((b)-1), j(0); j <= _n; j++) cmask |= 1 << (tmp[j] - 'a');
    q.cr(cmask);
    quer[i] = cmask;
  }
  memset(nx, 63, sizeof(nx));
  for (int i = (n - 1), _b = (0); i >= _b; i--) {
    nx[str[i] - 'a'] = i;
    int mask = 0;
    for (int _n((26) - 1), j(0); j <= _n; j++) ind[j] = j;
    sort(ind, ind + 26, cmp());
    int pp = -1;
    if (i) pp = str[i - 1] - 'a';
    for (int _n((26) - 1), j(0); j <= _n; j++) {
      int v = ind[j];
      if (nx[v] >= 1000000000) break;
      mask |= 1 << v;
      if (i && (mask & 1 << pp)) break;
      q.add(mask, 1);
    }
  }
  for (int _n((m)-1), i(0); i <= _n; i++) {
    printf("%d\n", q.fnd(quer[i]));
  }
}