#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:60000000")
using namespace std;
string S;
int k;
string forbidden[40];
int getans(char a, char b) {
  int ca = 0, cb = 0;
  int ret = 0;
  for (int i = 0; i < S.size(); i++) {
    if (S[i] == a)
      ca++;
    else if (S[i] == b)
      cb++;
    else {
      if (ca > 0 && cb > 0) {
        ret += min(ca, cb);
      }
      ca = 0;
      cb = 0;
    }
  }
  if (ca > 0 && cb > 0) {
    ret += min(ca, cb);
  }
  return ret;
}
int main() {
  cin >> S;
  scanf("%d", &k);
  int ans = 0;
  for (int i = 0; i < k; i++) {
    cin >> forbidden[i];
    ans += getans(forbidden[i][0], forbidden[i][1]);
  }
  cout << ans << endl;
  return 0;
}
