#include <bits/stdc++.h>
using namespace std;
map<char, char> mp;
int main() {
  string s, as = "";
  cin >> s;
  int k, ans = 0;
  cin >> k;
  for (int i = 0; i < k; i++) {
    string ss;
    cin >> ss;
    char c1 = ss[0], c2 = ss[1];
    mp[c1] = c2;
    mp[c2] = c1;
  }
  for (int i = 0; i < s.size(); i++) {
    char c1 = s[i], c2 = mp[s[i]];
    int j = 0;
    string ss = "";
    for (j = i; j < s.size(); j++) {
      if (s[j] == c1 || s[j] == c2) {
        ss += s[j];
      } else
        break;
    }
    int x = 0, y = 0;
    for (char ch : ss) {
      if (ch == c1)
        x++;
      else
        y++;
    }
    ans += min(x, y);
    i = j - 1;
  }
  cout << ans << endl;
}
