#include <bits/stdc++.h>
using namespace std;
int main() {
  string s;
  int k;
  cin >> s >> k;
  int result = 0;
  for (; k > 0; k--) {
    char a, b;
    cin >> a >> b;
    int l = 0, r = 0;
    for (int i = 0; i <= s.size(); i++) {
      if (s[i] == a)
        l++;
      else if (s[i] == b)
        r++;
      else {
        result += min(l, r);
        l = 0;
        r = 0;
      }
    }
  }
  cout << result << endl;
}
