#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-8;
string str;
int main() {
  while (cin >> str) {
    int n;
    scanf("%d", &n);
    int len = str.size();
    int ans = 0;
    for (int i = 1; i <= (int)(n); ++i) {
      char a, b;
      cin >> a >> b;
      for (int j = 0; j <= (int)(len - 1); ++j) {
        int x = 0, y = 0;
        while (str[j] == a || str[j] == b) {
          if (str[j] == a)
            x++;
          else
            y++;
          j++;
        }
        ans += min(x, y);
      }
    }
    printf("%d\n", ans);
  }
  return 0;
}
