#include <bits/stdc++.h>
using namespace std;
int a[100010], b[100010] = {0}, v[100010] = {0}, m[27][27], c[27] = {0};
char str[100010], s[2];
int main() {
  int n, n1, i, j, k, l1, l2, p1, p2, s2;
  char s1;
  memset(m, 0, 27 * 27 * sizeof(int));
  scanf("%s", &str);
  scanf("%d", &k);
  for (i = 0; i < k; i++) {
    scanf("%s", &s);
    p1 = s[0] - 96;
    p2 = s[1] - 96;
    m[p1][p2] = 1;
    m[p2][p1] = 1;
  }
  n = strlen(str);
  s1 = str[0];
  l1 = 1;
  n1 = 1;
  a[n1] = str[0] - 96;
  b[n1] = 1;
  for (i = 1; i < n; i++) {
    if (str[i] != s1) {
      n1++;
      a[n1] = str[i] - 96;
      l1 = 1;
      b[n1] = l1;
      s1 = str[i];
    } else {
      l1++;
      b[n1] = l1;
    }
  }
  a[0] = 0;
  p1 = 0;
  k = 1;
  for (i = 2; i <= n1; i++) {
    if (m[a[i]][a[i - 1]] == 1) {
      v[i - 1] = k;
      v[i] = k;
      p1 = 0;
    } else {
      if (p1 == 0) {
        k++;
        p1 = 1;
      }
    }
  }
  s2 = 0;
  k = 1;
  for (i = 1; i <= n1; i++) {
    if (v[i] == k) {
      c[a[i]] += b[i];
    } else if (v[i] == k + 1) {
      s2 += min(c[a[i - 1]], c[a[i - 2]]);
      c[a[i - 1]] = 0;
      c[a[i - 2]] = 0;
      c[a[i]] += b[i];
      k++;
    } else if (v[i] == 0) {
      s2 += min(c[a[i - 1]], c[a[i - 2]]);
      c[a[i - 1]] = 0;
      c[a[i - 2]] = 0;
    }
  }
  if (v[n1] == k) {
    s2 += min(c[a[i - 1]], c[a[i - 2]]);
  }
  printf("%d\n", s2);
  return 0;
}
