#include <bits/stdc++.h>
using namespace std;
bool isPrime(long long N) {
  for (long long i = 2; i * i <= N; ++i) {
    if (N % i == 0) return false;
  }
  return true;
}
bool sortinrev(const pair<int, int> &a, const pair<int, int> &b) {
  return (a.first > b.first);
}
int gcd(int a, int b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
bool comp(const pair<int, int> &a, const pair<int, int> &b) {
  if (a.first == b.first)
    return a.second < b.second;
  else
    return a.first > b.first;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long n, i, j, c1 = 0, c2 = 0, ans = 0;
  string s, p;
  cin >> s >> n;
  for (j = 0; j < n; j++) {
    cin >> p;
    c1 = 0;
    c2 = 0;
    for (i = 0; i < s.length(); i++) {
      if (s[i] == p[0]) {
        c1++;
      } else if (s[i] == p[1]) {
        c2++;
      } else {
        ans += min(c1, c2);
        c1 = 0;
        c2 = 0;
      }
    }
    ans += min(c1, c2);
  }
  cout << ans;
  return 0;
}
