#include <bits/stdc++.h>
using namespace std;
int main() {
  string s, t[15];
  int n, ans = 0;
  cin >> s;
  cin >> n;
  for (int i = 0; i < n; i++) cin >> t[i];
  for (int j = 0; j < n; j++) {
    int t1 = 0, t2 = 0;
    for (int i = 0; i < s.size(); i++) {
      if (s[i] == t[j][0])
        t1++;
      else {
        if (s[i] == t[j][1])
          t2++;
        else {
          ans += min(t1, t2);
          t1 = 0;
          t2 = 0;
        }
      }
    }
    ans += min(t1, t2);
  }
  cout << ans << endl;
}
