#include <bits/stdc++.h>
using namespace std;
struct Arco {
  int v, next;
  Arco() {}
  Arco(int v, int next) : v(v), next(next) {}
} edges[1];
int last[1], E;
void add_edge(int v, int u) {
  edges[E] = Arco(u, last[v]);
  last[v] = E++;
}
int xf[8] = {-1, -1, -1, 0, 0, +1, +1, +1};
int xc[8] = {-1, 0, +1, -1, +1, -1, 0, +1};
bool esta[30];
bool M[256][256];
int METODO(char *cad) {
  int sol = 0;
  return sol;
}
int main() {
  char texto[100004];
  char cad[10];
  int q;
  scanf("%s", texto);
  scanf("%d", &q);
  int sol = 0, len = strlen(texto);
  while (q--) {
    scanf("%s", cad);
    for (int i = 0; i < len; i++)
      if (texto[i] == cad[0] || texto[i] == cad[1]) {
        int a = 0, b = 0, j = i;
        while (j < len && (texto[j] == cad[0] || texto[j] == cad[1]))
          if (texto[j++] == cad[0])
            a++;
          else
            b++;
        sol += min(a, b);
        i = j;
      }
  }
  printf("%d\n", sol);
  return 0;
}
