#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, x, y, sum;
  string s;
  char a, b;
  cin >> s;
  cin >> n;
  sum = 0;
  while (n--) {
    cin >> a >> b;
    x = 0, y = 0;
    for (int i = 0; i < s.size(); i++) {
      if (s[i] == a)
        x++;
      else if (s[i] == b)
        y++;
      else {
        sum += min(x, y);
        x = 0;
        y = 0;
      }
    }
    sum += min(x, y);
  }
  cout << sum << endl;
  return 0;
}
