#include <bits/stdc++.h>
using namespace std;
int main() {
  char x[100000], a, b;
  int k, l, ans = 0;
  cin >> x >> k;
  l = strlen(x);
  for (int i = 0; i < k; i++) {
    cin >> a;
    cin >> b;
    for (int j = 0; j < l; j++) {
      int s1 = 0, s2 = 0;
      while (a == x[j] || b == x[j]) {
        if (a == x[j]) s1++;
        if (b == x[j]) s2++;
        j++;
      }
      ans += min(s1, s2);
    }
  }
  cout << ans;
  return 0;
}
