#include <bits/stdc++.h>
using namespace std;
struct pt {
  char c;
  int x;
};
string s;
int n, m, start, s1, s2, res;
char ch;
char a[30], b[30];
pt c[100005];
void init() {
  int x = 1;
  m = 1;
  c[0].c = 'z' + 1;
  c[1].c = s[0];
  s += " ";
  for (int i = 1; i <= s.length(); i++) {
    if (s[i] == s[i - 1]) {
      x++;
      continue;
    }
    c[m].x = x;
    m++;
    c[m].c = s[i];
    x = 1;
  }
}
int main() {
  if (0) {
    freopen("a.inp", "r", stdin);
  };
  getline(cin, s);
  scanf("%d%c", &n, &ch);
  for (int i = 0; i < n; i++) scanf("%c%c%c", &a[i], &b[i], &ch);
  init();
  for (int i = 0; i < n; i++) {
    s1 = 0;
    s2 = 0;
    for (int j = 1; j <= m; j++) {
      if (c[j].c != a[i] && c[j].c != b[i]) {
        if (c[j - 1].c != a[i] && c[j - 1].c != b[i]) continue;
        res += min(s1, s2);
        s1 = 0;
        s2 = 0;
        continue;
      }
      if (c[j - 1].c != a[i] && c[j - 1].c != b[i]) start = j;
      if (c[j].c == a[i]) s1 += c[j].x;
      if (c[j].c == b[i]) s2 += c[j].x;
    }
  }
  printf("%d\n", res);
}
