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