#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100000 + 50;
const int maxw = 100 + 20;
const int MAXNNODE = 1000000 + 10;
const long long LLMAX = 0x7fffffffffffffffLL;
const long long LLMIN = 0x8000000000000000LL;
const int INF = 0x7fffffff;
const int IMIN = 0x80000000;
const double PI = acos(-1.0);
string str1, str2;
int main() {
  int c0, c1, ans, n;
  while (cin >> str1) {
    cin >> n;
    ans = 0;
    for (int i = (0); i < (n); i++) {
      cin >> str2;
      for (int j = (0); j < (str1.size()); j++) {
        c1 = c0 = 0;
        while (j < str1.size() && (str1[j] == str2[0] || str1[j] == str2[1])) {
          if (str1[j] == str2[0])
            c0++;
          else
            c1++;
          j++;
        }
        ans += min(c1, c0);
      }
    }
    printf("%d\n", ans);
  }
  return 0;
}
