#include <bits/stdc++.h>
using namespace std;
int main() {
  string str, aux;
  int n, m, t, resp = 0;
  cin >> str;
  cin >> t;
  for (int(i) = (0); (i) < (t); ++(i)) {
    cin >> aux;
    for (int(j) = (0); (j) < (str.size()); ++(j)) {
      if (str[j] == aux[0] || str[j] == aux[1]) {
        n = 0, m = 0;
        for (int(k) = (j); (k) < (str.size()); ++(k)) {
          if (str[k] != aux[0] && str[k] != aux[1]) break;
          if (str[k] == aux[0]) n++;
          if (str[k] == aux[1]) m++;
          j++;
        }
        resp += min(n, m);
      }
    }
  }
  cout << resp << endl;
  return 0;
}
