#include <bits/stdc++.h>
using namespace std;
int main() {
  string s, s1;
  cin >> s;
  int k;
  cin >> k;
  long int ans = 0;
  for (int i = 0; i < k; i++) {
    cin >> s1;
    int n1 = 0, n2 = 0;
    for (int j = 0; j < s.length(); j++) {
      if (s[j] == s1[0])
        n1++;
      else if (s[j] == s1[1])
        n2++;
      else {
        ans += min(n1, n2);
        n1 = 0;
        n2 = 0;
      }
    }
    ans += min(n1, n2);
  }
  cout << ans << endl;
  return 0;
}
