#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
using ll = long long;
using pii = pair<int, int>;
const int MOD = 1e9 + 7;
const int INF = 1e9 + 1e2;
void stndrtn() {}
const bool flag = 0;
void ma1n() {
  string s;
  cin >> s;
  int k;
  cin >> k;
  int n = (int)s.size();
  int ans = 0;
  for (string t; k--;) {
    cin >> t;
    vector<int> c(2);
    for (int i = 0; i < n; ++i) {
      if (s[i] == t[0] || s[i] == t[1]) {
        if (s[i] == t[0]) {
          c[0]++;
        } else {
          c[1]++;
        }
      } else {
        ans += min(c[0], c[1]);
        c[0] = c[1] = 0;
      }
    }
    ans += min(c[0], c[1]);
  }
  cout << ans;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(nullptr), stndrtn();
  int ts = 1;
  if (flag) {
    cin >> ts;
  }
  while (ts--) {
    ma1n();
  }
  return 0;
}
