#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  long i, n, k, ans = 0, j, a, b;
  string s, p;
  cin >> s;
  n = s.size();
  cin >> k;
  while (k--) {
    cin >> p;
    a = b = 0;
    for (i = 0; i < n; i++) {
      for (; (s[i] == p[0] || s[i] == p[1]) && i < n; i++) {
        if (s[i] == p[0])
          a++;
        else
          b++;
      }
      if (a > 0 && b > 0) i--;
      ans += min(a, b);
      a = b = 0;
    }
  }
  cout << ans;
  return 0;
}
