#include <bits/stdc++.h>
int n, m;
char s[1000000];
int p[100];
int main() {
  scanf("%s", s);
  n = strlen(s);
  for (int i = 0; i < n; i++) s[i] -= 'a';
  scanf("%d", &m);
  for (int i = 0; i < 50; i++) p[i] = 50;
  for (int i = 0; i < m; i++) {
    char tmp[5];
    scanf("%s", tmp);
    tmp[0] -= 'a';
    tmp[1] -= 'a';
    p[tmp[0]] = tmp[1];
    p[tmp[1]] = tmp[0];
  }
  int ans = 0;
  for (int i = 0; i < n; i++) {
    int left, right;
    left = i;
    right = i;
    for (; right < n;) {
      if (s[right] == s[left] || s[right] == p[s[left]])
        right++;
      else
        break;
    }
    right--;
    int a = 0, b = 0;
    for (int j = left; j <= right; j++) {
      if (s[j] == s[left]) a++;
      if (s[j] == p[s[left]]) b++;
    }
    if (a > b)
      ans += b;
    else
      ans += a;
    i = right;
  }
  printf("%d\n", ans);
}
