#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  string st;
  cin >> st;
  int k, fi, se, cnt = 0;
  cin >> k;
  for (int i = 0; i < k; i++) {
    char a, b;
    cin >> a >> b;
    fi = se = 0;
    for (int j = 0; j < st.length(); j++) {
      if (st[j] == a)
        fi++;
      else if (st[j] == b)
        se++;
      else {
        cnt += min(fi, se);
        fi = se = 0;
      }
    }
    cnt += min(fi, se);
  }
  cout << cnt << endl;
  return 0;
}
