#include <bits/stdc++.h>
using namespace std;
int main() {
  string t;
  cin >> t;
  int n;
  cin >> n;
  int ans = 0;
  while (n--) {
    int x = 0, y = 0;
    char a, b;
    cin >> a >> b;
    for (int i = 0; i < t.size(); i++) {
      if (t[i] == a)
        x++;
      else if (t[i] == b)
        y++;
      else {
        ans += min(x, y);
        x = 0, y = 0;
      }
    }
    if (x > 0 && y > 0) {
      ans += min(x, y);
    }
  }
  cout << ans;
}
