#include <bits/stdc++.h>
using namespace std;
int main() {
  string str;
  cin >> str;
  long long k;
  cin >> k;
  pair<char, char> arr[k];
  for (long long i = 0; i < k; i++) {
    char a, b;
    cin >> a >> b;
    arr[i] = make_pair(min(a, b), max(a, b));
  }
  long long len = str.length();
  long long cnt = 0;
  for (long long j = 0; j < k; j++) {
    char a = arr[j].first;
    char b = arr[j].second;
    for (long long i = 0; i < len; i++) {
      long long ca = 0, cb = 0;
      if (str[i] == a || str[i] == b) {
        while (i < len && (str[i] == a || str[i] == b)) {
          if (str[i] == a)
            ca++;
          else
            cb++;
          i++;
        }
        if (ca < cb)
          cnt += ca;
        else
          cnt += cb;
      }
    }
  }
  cout << cnt << endl;
}
