#include <bits/stdc++.h>
using namespace std;
void solve() {
  string s;
  cin >> s;
  int n = s.size();
  vector<int> st(26, -1);
  int k;
  cin >> k;
  for (int i = 0; i < int(k); i++) {
    string t;
    cin >> t;
    st[t[0] - 'a'] = t[1] - 'a';
    st[t[1] - 'a'] = t[0] - 'a';
  }
  int ans = 0;
  for (int i = 0; i < (int)n; i++) {
    int a = st[s[i] - 'a'];
    int b = s[i] - 'a';
    int cnta = 0, cntb = 0;
    while (i < n && (s[i] - 'a' == a || s[i] - 'a' == b)) {
      if (s[i] - 'a' == a) {
        cnta++;
      } else {
        cntb++;
      }
      i++;
    }
    if (cnta > 0 || cntb > 0) i--;
    ans += min(cnta, cntb);
  }
  cout << ans << endl;
  ;
}
int main() {
  int t = 1;
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  while (t--) {
    solve();
  }
  return 0;
}
