#include <bits/stdc++.h>
using namespace std;
template <class T>
inline T INT_LEN(T v) {
  int len = 1;
  while (v /= 10) ++len;
  return len;
}
template <class T>
inline T xmlt(T X0, T Y0, T X1, T Y1, T X2, T Y2) {
  return (X1 - X0) * (Y2 - Y0) - (X2 - X0) * (Y1 - Y0);
}
char S[100005], tb[300], str[3];
int k;
void solve(char *sr, int k) {
  int i, j, n = (int)strlen(sr);
  int ans = 0;
  memset(tb, 0, sizeof(tb));
  while (k--) {
    scanf("%s", str);
    tb[str[0]] = str[1];
    tb[str[1]] = str[0];
  }
  for (i = j = 0; i < n; i = j) {
    if (tb[sr[i]]) {
      int c1 = 0, c2 = 0;
      while (sr[j] && (sr[j] == sr[i] || sr[i] == tb[sr[j]])) {
        if (sr[i] == sr[j])
          c1++;
        else
          c2++;
        j++;
      }
      ans += min(c1, c2);
    } else {
      j++;
    }
  }
  cout << ans << endl;
}
int main(void) {
  while (~scanf("%s", S)) {
    scanf("%d", &k);
    solve(S, k);
  }
  return 0;
}
