#include <bits/stdc++.h>
using namespace std;
int a[25] = {2,  3,  5,  7,  11, 13, 17, 19, 23, 29, 31, 37, 41,
             43, 47, 53, 59, 61, 67, 69, 71, 73, 79, 83, 97};
int main() {
  string lang;
  cin >> lang;
  int num;
  cin >> num;
  string ab;
  vector<int> c(26, 0);
  bool change = false, in = true;
  int ans = 0;
  while (num--) {
    cin >> ab;
    for (int i = 0; i < lang.length(); i++) {
      if (lang[i] == ab[0] || lang[i] == ab[1]) {
        c[lang[i] - 'a']++;
        in = true;
        change = true;
      } else {
        in = false;
      }
      if (!in && change) {
        ans += min(c[ab[0] - 'a'], c[ab[1] - 'a']);
        c[ab[0] - 'a'] = 0;
        c[ab[1] - 'a'] = 0;
        change = false;
      }
    }
    ans += min(c[ab[0] - 'a'], c[ab[1] - 'a']);
    c[ab[0] - 'a'] = 0;
    c[ab[1] - 'a'] = 0;
  }
  cout << ans << endl;
}
