#include <bits/stdc++.h>
using namespace std;
int main() {
  string s;
  int k, n, cnt = 0;
  cin >> s >> k;
  s += '#';
  n = s.size();
  for (int j = 0; j < k; j++) {
    char u, v;
    cin >> u >> v;
    int l = 0, r = 0;
    for (int i = 0; i < n; i++) {
      if (s[i] == u)
        l++;
      else if (s[i] == v)
        r++;
      else {
        cnt += min(l, r);
        l = r = 0;
      }
    }
  }
  cout << cnt << endl;
  return 0;
}
