#include <bits/stdc++.h>
using namespace std;
char s[100010], forb[15][4];
int ans;
int main() {
  int x, y, len, i, k, j;
  scanf("%s", s);
  len = strlen(s);
  scanf("%d", &k);
  for (i = 1; i <= k; i++) {
    scanf("%s", forb[i]);
    x = y = 0;
    for (j = 0; j < len; j++) {
      if (s[j] == forb[i][0])
        x++;
      else if (s[j] == forb[i][1])
        y++;
      else {
        ans += min(x, y);
        x = y = 0;
      }
    }
    ans += min(x, y);
  }
  printf("%d\n", ans);
}
