#include <bits/stdc++.h>
using namespace std;
int m[27][27];
char s[100010];
char p[40][2];
int main() {
  scanf("%s", s);
  int len = strlen(s);
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    char nn[10];
    scanf("%s", nn);
    p[i][0] = nn[0];
    p[i][1] = nn[1];
  }
  int res = 0, i = 0;
  while (i < len - 1) {
    int j = i;
    char x = s[j], y;
    bool f = false;
    for (int k = 0; k < n; k++) {
      if (p[k][0] == x) {
        y = p[k][1];
        f = true;
      } else if (p[k][1] == x) {
        y = p[k][0];
        f = true;
      }
    }
    if (f) {
      while ((s[j + 1] == x || s[j + 1] == y) && j + 1 < len) j++;
      int cx = 0, cy = 0;
      for (long long k = i; k <= j; k++) {
        if (s[k] == x)
          cx++;
        else if (s[k] == y)
          cy++;
      }
      res += min(cx, cy);
      i = j + 1;
    } else
      i++;
  }
  printf("%d", res);
  return 0;
}
