#include <bits/stdc++.h>
using namespace std;
string str;
long long int n, k;
int main() {
  string temp;
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long int a, b, i, j, cnt = 0;
  cin >> str;
  n = str.size();
  cin >> k;
  for (i = 0; i < k; i++) {
    cin >> temp;
    for (j = 0; j < n; j++) {
      a = 0, b = 0;
      while (j < n && (str[j] == temp[0] || str[j] == temp[1])) {
        if (str[j] == temp[0])
          a++;
        else
          b++;
        j++;
      }
      cnt += min(a, b);
    }
  }
  cout << cnt << '\n';
  return 0;
}
