#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  string s;
  cin >> s;
  int n = s.size();
  int k;
  cin >> k;
  vector<pair<char, char>> pr(k + 1);
  vector<int> a(26, 0);
  for (int i = 0; i < k; i++) {
    string forp;
    cin >> forp;
    sort(forp.begin(), forp.end());
    pr[i + 1] = {forp[0], forp[1]};
    a[forp[0] - 'a'] = a[forp[1] - 'a'] = i + 1;
  }
  int ans = 0;
  int pnow, c1 = 0, c2 = 0;
  pnow = a[s[0] - 'a'];
  if (s[0] == pr[pnow].first)
    c1++;
  else
    c2++;
  for (int i = 1; i < n; i++) {
    if (pnow == a[s[i] - 'a']) {
      if (s[i] == pr[pnow].first)
        c1++;
      else
        c2++;
    } else {
      ans += min(c1, c2);
      c1 = c2 = 0;
      pnow = a[s[i] - 'a'];
      if (s[i] == pr[pnow].first)
        c1++;
      else
        c2++;
    }
  }
  ans += min(c1, c2);
  cout << ans << "\n";
  return 0;
}
