#include <bits/stdc++.h>
using namespace std;
string s;
int a[100000 + 5];
map<char, int> m;
int main() {
  cin >> s;
  int n = ((int)s.size());
  int k = ({
    int x;
    scanf("%d", &x);
    x;
  });
  for (int i = (0); i < (k); i += (1)) {
    string ss;
    cin >> ss;
    for (int j = (0); j < (2); j += (1)) m[ss[j]] = i + 1;
  }
  for (int i = (0); i < (n); i += (1)) {
    a[i] = m[s[i]];
  }
  a[n] = -1;
  int p = 0;
  int ans = 0;
  for (int i = (1); i < (n + 1); i += (1)) {
    if (a[i] != a[i - 1]) {
      int x = count(s.begin() + p, s.begin() + i, s[p]);
      if (a[p]) ans += min(x, i - p - x);
      p = i;
    }
  }
  cout << ans << endl;
}
