#include <bits/stdc++.h>
using namespace std;
char s[123456], f[3];
int main() {
  scanf("%s", s);
  int k;
  scanf("%d", &k);
  int ans = 0;
  while (k--) {
    scanf("%s", f);
    for (int i = 0; s[i]; ++i)
      if (s[i] == f[0] || s[i] == f[1]) {
        int j = i;
        int first = 0, second = 0;
        while (s[j] == f[0] || s[j] == f[1]) {
          if (s[j] == f[0])
            ++first;
          else
            ++second;
          ++j;
        }
        ans += min(first, second);
        i = j - 1;
      }
  }
  printf("%d\n", ans);
  return 0;
}
