#include <bits/stdc++.h>
using namespace std;
int main(int argc, char** argv) {
  ios::sync_with_stdio(false);
  string str, s;
  int k, ans = 0;
  cin >> str >> k;
  for (int i = 0; i < k; ++i) {
    cin >> s;
    int p = 0;
    while (p < str.length()) {
      int t = p;
      bool f = false;
      map<char, int> mp;
      while (t < str.length() && (str[t] == s[0] || str[t] == s[1])) {
        f = true;
        mp[str[t]] += 1;
        t += 1;
      }
      if (!f) t += 1;
      ans += min(mp[s[0]], mp[s[1]]);
      p = t;
    }
  }
  cout << ans << endl;
  return 0;
}
