#include <bits/stdc++.h>
using namespace std;
int n, ans;
string str, STR;
string s[20];
void getans(char a, char b) {
  int ca = 0, cb = 0;
  for (int i = 0; i < str.size(); i++)
    if (str[i] == a)
      ca++;
    else if (str[i] == b)
      cb++;
    else {
      if (ca > 0 && cb > 0) ans += min(ca, cb);
      ca = 0;
      cb = 0;
    }
  ans += min(ca, cb);
}
int main() {
  cin >> str;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    cin >> s[i];
    getans(s[i][0], s[i][1]);
  }
  cout << ans << endl;
}
