#include <bits/stdc++.h>
using namespace std;
const int INF = 1000000000;
const double EPS = 1e-9;
int main() {
  string s;
  cin >> s;
  int n = s.size();
  int k;
  scanf("%d", &k);
  int ans = 0;
  for (int i = 0; i < k; i++) {
    char x[5];
    scanf("%s", x);
    int a = 0;
    int b = 0;
    for (int j = 0; j < n; j++)
      if (s[j] == x[0])
        a++;
      else if (s[j] == x[1])
        b++;
      else {
        ans += min(a, b);
        a = b = 0;
      }
    ans += min(a, b);
  }
  printf("%d\n", ans);
  return 0;
}
