#include <bits/stdc++.h>
using namespace std;
inline long long int gcd(long long int a, long long int b) {
  return b ? gcd(b, a % b) : a;
}
inline long long int fast_pow(long long int a, long long int b,
                              long long int mod) {
  long long int res = 1;
  a %= mod;
  while (b > 0) {
    if (b & 1) res = res * a % mod;
    b >>= 1;
    a = a * a % mod;
  }
  return res;
}
inline bool isPrime(long long int a) {
  for (long long int i = 2; i * i <= a; i++)
    if (a % i == 0) return 0;
  return 1;
}
string s, alpha_pairs;
int k, ans, cnt1, cnt2;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(NULL);
  cin >> s >> k;
  for (int i = 0; i < k; i++) {
    cin >> alpha_pairs;
    cnt1 = cnt2 = 0;
    for (int j = 0; j < s.size(); j++) {
      if (alpha_pairs[0] == s[j]) {
        cnt1++;
      } else if (alpha_pairs[1] == s[j]) {
        cnt2++;
      } else {
        ans += min(cnt1, cnt2);
        cnt1 = cnt2 = 0;
      }
    }
    ans += min(cnt1, cnt2);
  }
  cout << ans << '\n';
  return 0;
}
