#include <bits/stdc++.h>
using namespace std;
const double EPS = 1e-8;
namespace std {
bool operator<(const complex<double>& a, const complex<double>& b) {
  return real(a) != real(b) ? real(a) > real(b) : imag(a) > imag(b);
}
}  // namespace std
char s[110011];
char w[20][4];
int main() {
  scanf("%s", s);
  int n;
  scanf("%d", &n);
  for (int i = (0); i < (int)(n); i++) {
    scanf("%s", w[i]);
  }
  int ans = 0;
  int i = 0;
  while (s[i + 1]) {
    int f = -1;
    for (int j = (0); j < (int)(n); j++) {
      if ((s[i] == w[j][0] && s[i + 1] == w[j][1]) ||
          (s[i + 1] == w[j][0] && s[i] == w[j][1])) {
        f = j;
      }
    }
    if (f == -1) {
      i++;
      continue;
    }
    int j = i;
    while (s[j] == w[f][0] || s[j] == w[f][1]) {
      j++;
    }
    while (i > 0 && s[i] == s[i - 1]) i--;
    while (j < n && s[j - 1] == s[j]) j++;
    int cf = 0;
    for (int k = (i); k < (int)(j); k++) {
      cf += s[k] == w[f][0];
    }
    ans += min(cf, j - i - cf);
    i = j;
  }
  printf("%d\n", ans);
  return 0;
}
