#include <bits/stdc++.h>
using namespace std;
const int num = 200001;
int fl[num];
map<char, int> m;
string forb[14];
int main() {
  int n, ind, x, y;
  string str;
  cin >> str >> n;
  for (int i = 1; i < n + 1; i++) {
    cin >> forb[i];
  }
  for (int i = 0; i < str.size(); i++) {
    for (int j = 1; j < n + 1; j++) {
      if (str[i] == forb[j][0] || str[i] == forb[j][1]) fl[i] = j;
    }
  }
  int cnt = 0;
  int ans = 0;
  for (int i = 0; i < str.size(); i++) {
    if (fl[i]) {
      int j = i;
      ind = fl[j];
      cnt = 0;
      while (fl[j] == ind && j < str.size()) m[str[j]]++, j++, cnt++;
      x = m[forb[ind][0]];
      y = m[forb[ind][1]];
      ans += min(x, y);
      if (j == str.size()) {
        cout << ans << "\n";
        return 0;
      }
      i = j - 1;
      m.clear();
    }
  }
  cout << ans << "\n";
  return 0;
}
