#include <bits/stdc++.h>
using namespace std;
int main() {
  string ss;
  cin >> ss;
  int n = ss.length();
  int k;
  cin >> k;
  long long ans = 0;
  for (int i = 0; i < k; i++) {
    string s1;
    cin >> s1;
    char a = s1[0], b = s1[1];
    unordered_map<char, int> m;
    int st = 0;
    for (int i = 0; i < n; i++) {
      if (ss[i] == a || ss[i] == b) {
        m[ss[i]]++;
        st++;
      } else if (st != 0) {
        ans = ans + min(m[a], m[b]);
        m[a] = 0;
        m[b] = 0;
      }
    }
    if (st != 0) {
      ans = ans + min(m[a], m[b]);
      m[a] = 0;
      m[b] = 0;
    }
  }
  cout << ans;
  return 0;
}
