#include <bits/stdc++.h>
using namespace std;
int main() {
  int group[26], minv[26], maxv[26];
  string s;
  int n, res = 0;
  char c1, c2;
  for (int i = 0; i < 26; i++) {
    group[i] = minv[i] = maxv[i] = i;
  }
  cin >> s >> n;
  for (int i = 0; i < n; i++) {
    cin >> c1 >> c2;
    if (c1 > c2) swap(c1, c2);
    group[c2 - 'a'] = group[c1 - 'a'];
    minv[group[c1 - 'a']] = c1 - 'a';
    maxv[group[c2 - 'a']] = c2 - 'a';
  }
  int st, ed, p, cntMin, cntMax;
  st = ed = p = 0;
  cntMin = cntMax = 0;
  if ((s[0] - 'a') == minv[group[s[0] - 'a']]) {
    cntMin++;
  } else {
    cntMax++;
  }
  while (++p && p <= s.length()) {
    if (p == s.length() || group[s[p] - 'a'] != group[s[p - 1] - 'a']) {
      res += min(cntMin, cntMax);
      st = ed = p;
      cntMin = cntMax = 0;
    } else {
      ed++;
    }
    if (p < s.length()) {
      if ((s[p] - 'a') == minv[group[s[p] - 'a']]) {
        cntMin++;
      } else {
        cntMax++;
      }
    }
  }
  cout << res << endl;
  return 0;
}
