#include <bits/stdc++.h>
using namespace std;
int getMinCount(string& s, vector<string>& f, int K) {
  int ans = 0;
  for (int i = 0; i < K; i++) {
    int start = -1, end = -1;
    for (int j = 0; j < s.length(); j++) {
      if (s[j] == f[i][0] || s[j] == f[i][1]) {
        if (start == -1) start = j;
        end = j;
      } else {
        int c1 = 0, c2 = 0;
        for (int k = start; k <= end; k++) {
          if (s[k] == f[i][0])
            c1++;
          else
            c2++;
        }
        ans += min(c1, c2);
        start = end = -1;
      }
    }
    int c1 = 0, c2 = 0;
    for (int k = start; k <= end; k++) {
      if (s[k] == f[i][0])
        c1++;
      else
        c2++;
    }
    ans += min(c1, c2);
  }
  return ans;
}
int main() {
  string s;
  getline(cin, s);
  int k;
  scanf("%d%*c", &k);
  vector<string> f(k);
  for (int i = 0; i < k; i++) {
    getline(cin, f[i]);
  }
  cout << getMinCount(s, f, k) << endl;
  return 0;
}
