#include <bits/stdc++.h>
using namespace std;
int32_t main() {
  string s;
  cin >> s;
  long long t;
  cin >> t;
  long long n = s.length();
  long long ans = 0;
  while (t--) {
    char a, b;
    cin >> a >> b;
    long long i = 0, ac = 0, bc = 0;
    bool pending = 0;
    while (i < n) {
      if (s[i] == a or s[i] == b) {
        pending = 1;
        if (s[i] == a)
          ac++;
        else
          bc++;
      } else {
        ans += min(ac, bc);
        ac = bc = 0;
        pending = 0;
      }
      i++;
    }
    if (pending) {
      ans += min(ac, bc);
      pending = 0;
    }
  }
  cout << ans;
}
