#include <bits/stdc++.h>
using namespace std;
int main() {
  string s = "";
  cin >> s;
  int k;
  cin >> k;
  vector<pair<char, char> > f(k);
  for (int i = 0; i < (k); i++) {
    string t = "";
    cin >> t;
    f[i].first = t[0];
    f[i].second = t[1];
  }
  s += '_';
  int res = 0;
  for (int i = 0; i < (k); i++) {
    int n[2] = {0};
    int curr = 0;
    for (int j = 0; j < (s.size()); j++) {
      if (s[j] == f[i].first) {
        n[0]++;
      } else if (s[j] == f[i].second) {
        n[1]++;
      } else {
        curr = min(n[0], n[1]);
        res += curr;
        n[0] = 0, n[1] = 0;
      }
    }
  }
  cout << res << endl;
  return 0;
}
