#include <bits/stdc++.h>
using namespace std;
int main() {
  string s, s1;
  cin >> s;
  int k;
  cin >> k;
  int ans = 0;
  for (int i = 0; i < k; i++) {
    cin >> s1;
    int l = 0;
    int r = 0;
    int c1 = 0;
    int c2 = 0;
    int p = 0;
    for (int j = 0; j < s.size(); j++) {
      int k = j;
      while (k < s.size() && s[k] == s1[0] || s[k] == s1[1]) {
        if (s[k] == s1[0])
          c1++;
        else if (s[k] == s1[1])
          c2++;
        k++;
      }
      ans += min(c1, c2);
      c1 = 0;
      c2 = 0;
      if (j != k) j = k - 1;
    }
  }
  cout << ans;
  return 0;
}
