#include <bits/stdc++.h>
using namespace std;
string text;
int main() {
  int K;
  int ans = 0;
  getline(cin, text);
  int lent = text.size();
  scanf("%d\n", &K);
  for (int k = 0; k < K; k++) {
    char a, b;
    cin >> a;
    cin >> b;
    for (int i = 0; i < lent; i++) {
      int left = 0, right = 0;
      while (text[i] == a || text[i] == b) {
        if (text[i] == a) left++;
        if (text[i] == b) right++;
        i++;
      }
      ans += min(left, right);
    }
  }
  printf("%d\n", ans);
  return 0;
}
