#include <bits/stdc++.h>
using namespace std;
const int maxN = 100000 + 10;
char str[maxN], tmp[maxN];
int tot[maxN];
int nt;
int edg[128][128];
int main() {
  scanf("%s", str);
  int L = strlen(str);
  memset(edg, 0, sizeof(edg));
  int K;
  scanf("%d", &K);
  char ss[5];
  for (int i = 0; i < K; ++i) {
    scanf("%s", ss);
    edg[(int)ss[0]][(int)ss[1]] = edg[(int)ss[1]][(int)ss[0]] = 1;
  }
  nt = 0;
  for (int i = 0, j; i < L;) {
    tmp[nt] = str[i];
    tot[nt] = 0;
    j = i;
    while (j < L && str[j] == str[i]) ++tot[nt], ++j;
    i = j;
    nt++;
  }
  int ans = 0;
  for (int i = 0, j, k; i < nt;) {
    j = i + 1;
    while (j < nt && edg[(int)tmp[j]][(int)tmp[j - 1]]) ++j;
    int p = 0, q = 0;
    for (k = i; k < j; ++k)
      if (k & 1)
        p += tot[k];
      else
        q += tot[k];
    ans += min(p, q);
    i = j;
  }
  printf("%d\n", ans);
  return 0;
}
