#include <bits/stdc++.h>
using namespace std;
int main() {
  string s;
  int k, ans = 0;
  cin >> s >> k;
  char a, b;
  int cnta, cntb;
  s += '#';
  for (int i = 0; i < k; i++) {
    cin >> a >> b;
    cnta = 0;
    cntb = 0;
    for (int j = 0; j < s.size(); j++) {
      if (s[j] == a)
        cnta++;
      else if (s[j] == b)
        cntb++;
      else {
        ans += min(cnta, cntb);
        cnta = 0;
        cntb = 0;
      }
    }
  }
  cout << ans;
  return 0;
}
