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