#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
const long long MX = 1e9;
const long long INF = 1e9;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n, k;
  string s;
  cin >> s >> k;
  string p[k];
  for (int i = 0; i < k; ++i) cin >> p[i];
  int ans = 0, l1, l2;
  n = s.length();
  for (int i = 0; i < k; ++i) {
    l1 = l2 = 0;
    for (int j = 0; j < n; ++j) {
      if (s[j] == p[i][0])
        ++l1;
      else if (s[j] == p[i][1])
        ++l2;
      else {
        ans += min(l1, l2);
        l1 = l2 = 0;
      }
    }
    ans += min(l1, l2);
  }
  cout << ans << '\n';
  return 0;
}
