#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
using namespace std;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long i, j, k, n, l, t, m = 0;
  string s, d;
  vector<pair<char, char>> a;
  cin >> s >> t;
  n = s.size();
  for (long long i = 0; i < t; i++) {
    cin >> d;
    a.push_back({d[0], d[1]});
  }
  for (long long i = 0; i < t; i++) {
    for (long long j = 0; j < n; j++) {
      k = 0, l = 0;
      while ((j < n) && ((s[j] == a[i].first) || ((s[j] == a[i].second)))) {
        if (s[j] == a[i].first)
          k++;
        else
          l++;
        j++;
        if (j == n) break;
      }
      m += min(l, k);
    }
  }
  cout << m;
  return 0;
}
