#include <bits/stdc++.h>
using namespace std;
const int N = 100005;
int k, mark[256];
char s[N], f[2];
int main() {
  cin >> s;
  int l = strlen(s);
  cin >> k;
  for (int i = 0; i < 256; i++) mark[i] = -2;
  for (int i = 0; i < k; i++) {
    cin >> f;
    mark[f[0]] = 2 * i;
    mark[f[1]] = 2 * i + 1;
  }
  int best = 0;
  for (int i = 0; i < l; i++)
    if (mark[s[i]] != -2) {
      int j = i, z[2] = {0, 0};
      while (j < l && mark[s[j]] / 2 == mark[s[i]] / 2) {
        z[mark[s[j]] % 2]++;
        j++;
      }
      best += min(z[0], z[1]);
      i = j - 1;
    }
  cout << best << endl;
}
