#include <bits/stdc++.h>
using namespace std;
char a[111111];
int nn, e, p, ans = 0, n, aa, bb;
string s;
int main() {
  gets(a);
  nn = strlen(a);
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> s;
    aa = 0;
    bb = 0;
    for (int j = 0; j < nn; j++) {
      if (a[j] != s[0] && a[j] != s[1]) {
        ans += min(aa, bb);
        aa = 0;
        bb = 0;
      }
      if (a[j] == s[0]) aa++;
      if (a[j] == s[1]) bb++;
    }
    ans += min(aa, bb);
  }
  cout << (ans) << endl;
  return 0;
}
