#include <bits/stdc++.h>
using namespace std;
inline void boostIO() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}
int main() {
  boostIO();
  int n, a, b, i, j, ans = 0;
  string s, t;
  vector<string> p;
  cin >> s >> n;
  for (i = 0; i < n; ++i) {
    cin >> t;
    p.push_back(t);
  }
  for (j = 0; j < n; ++j) {
    a = b = 0;
    t = p[j];
    for (i = 0; i < s.size(); ++i) {
      if (s[i] == t[0])
        ++a;
      else if (s[i] == t[1])
        ++b;
      else
        ans += min(a, b), a = b = 0;
    }
    ans += min(a, b);
  }
  cout << ans << endl;
  return 0;
}
