#include <bits/stdc++.h>
using namespace std;
int n, m, ans;
char S[int(1e5 + 5)];
set<pair<int, int> > Set;
int main() {
  scanf("%s", S + 1);
  n = strlen(S + 1);
  scanf("%d", &m);
  while (m--) {
    char s[2];
    cin >> s;
    Set.insert(make_pair(s[0], s[1]));
    Set.insert(make_pair(s[1], s[0]));
  }
  for (auto it = Set.begin(); it != Set.end(); it++) {
    char f = (*it).first;
    char s = (*it).second;
    for (int i = 1; i <= n;) {
      if (S[i] == f || S[i] == s) {
        int from = i, to = i, c1 = 0, c2 = 0;
        bool foo = false, bar = false;
        if (S[i] == f)
          foo = true;
        else
          bar = true;
        while ((S[to] == f || S[to] == s) && to <= n) {
          if (S[to] == f) {
            foo = true;
            c1++;
          } else {
            bar = true;
            c2++;
          }
          to++;
        }
        if (foo & bar) {
          for (int j = i; j < to; j++) {
            S[j] = (c1 < c2 ? s : f);
          }
          ans += min(c1, c2);
        }
        i = to;
      } else {
        i++;
      }
    }
  }
  cout << ans << endl;
  return 0;
}
