#include <bits/stdc++.h>
using namespace std;
char in[100100];
int K;
char pr[30];
int main() {
  gets(in);
  scanf("%d\n", &K);
  char buff[5];
  for (int i = 0; i < (30); ++i) pr[i] = 30;
  for (int i = 0; i < (K); ++i) {
    gets(buff);
    pr[buff[0] - 'a'] = buff[1] - 'a';
    pr[buff[1] - 'a'] = buff[0] - 'a';
  }
  int i = 0;
  int res = 0;
  while (in[i]) {
    int c1 = in[i] - 'a';
    int c2 = pr[c1];
    if (c2 == 30) {
      ++i;
      continue;
    }
    int begin = i;
    while (in[i + 1] - 'a' == c1 || in[i + 1] - 'a' == c2) ++i;
    int end = i;
    int c1c = 0, c2c = 0;
    for (int j = (begin); j <= (end); ++j) {
      if (in[j] - 'a' == c1)
        ++c1c;
      else
        ++c2c;
    }
    res += min(c1c, c2c);
    i = end + 1;
  }
  printf("%d\n", res);
  return 0;
}
