#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, l, ans = 0, first, second;
  string s;
  char a, b;
  cin >> s;
  cin >> n;
  l = s.size();
  while (n--) {
    cin >> a >> b;
    for (int i = 0; i < l; i++) {
      first = second = 0;
      while (s[i] == a || s[i] == b) {
        s[i] == a ? first++ : second++;
        i++;
      }
      ans += min(first, second);
    }
  }
  cout << ans;
  return 0;
}
