#include <bits/stdc++.h>
using namespace std;
int n;
string str, _2v;
int main() {
  cin >> str;
  cin >> n;
  int res = 0;
  for (int i = 0; i < n; i++) {
    cin >> _2v;
    int cnt1 = 0, cnt2 = 0;
    for (auto &s : str) {
      if (s == _2v[0])
        cnt1++;
      else if (s == _2v[1])
        cnt2++;
      else
        res += min(cnt1, cnt2), cnt1 = 0, cnt2 = 0;
    }
    res += min(cnt1, cnt2);
  }
  cout << res << "\n";
  return 0;
}
