#include <bits/stdc++.h>
char str[100010], ch[5];
int main() {
  int n, i, a, b;
  while (scanf("%s%d", str, &n) != EOF) {
    int len = strlen(str), ans = 0;
    while (n--) {
      scanf("%s", ch);
      for (i = a = b = 0; i <= len; i++) {
        if (str[i] == ch[0])
          a++;
        else if (str[i] == ch[1])
          b++;
        else {
          ans += a > b ? b : a;
          a = b = 0;
        }
      }
    }
    printf("%d\n", ans);
  }
  return 0;
}
