#include <bits/stdc++.h>
using namespace std;
int main() {
  string s;
  string k;
  int m;
  cin >> s;
  cin >> m;
  int a, b;
  int sum = 0;
  for (int i = 0; i < m; i++) {
    cin >> k;
    a = 0;
    b = 0;
    for (int j = 0; j < s.size(); j++) {
      if (k[0] == s[j])
        a++;
      else if (k[1] == s[j])
        b++;
      else {
        sum += min(a, b);
        a = 0;
        b = 0;
      }
    }
    sum += min(a, b);
  }
  printf("%d\n", sum);
  return 0;
}
