#include <bits/stdc++.h>
using namespace std;
const long long int mod = 1e9 + 7;
char a[200005] = {'*'}, b[200005] = {'*'};
vector<pair<long long int, long long int> > v;
stack<char> st;
int main() {
  long long int i, j, k, nb = 0, x, y, m, l, n, sc = 0, nbround = 1;
  string s, ch;
  cin >> s;
  n = s.size();
  cin >> m;
  for (i = 1; i <= m; i++) {
    cin >> ch;
    long long int idx = 0;
    while (idx < n) {
      long long int nb1 = 0, nb2 = 0;
      j = idx;
      while ((s[j] == ch[0] || s[j] == ch[1]) && j < n) {
        if (s[j] == ch[0])
          nb1++;
        else
          nb2++;
        j++;
      }
      nb += min(nb1, nb2);
      if (j != idx)
        idx = j;
      else
        idx++;
    }
  }
  cout << nb;
}
