#include <bits/stdc++.h>
using namespace std;
class node {
 public:
  long long int second;
  long long int length;
};
int main() {
  string s;
  long long int n, k, i, val1, val2, counter1, counter2, j;
  char last = '0';
  char a, b;
  cin >> s;
  n = s.length();
  map<char, char> mapper;
  vector<pair<long long int, long long int> > forbidden;
  cin >> k;
  long long int ans = 0;
  for (i = 0; i < k; i++) {
    getchar();
    scanf("%c%c", &a, &b), mapper[a] = b, mapper[b] = a;
  }
  for (i = 0; i < n;) {
    for (j = i, counter1 = 0, counter2 = 0; j < n; j++) {
      if (s[j] == mapper[s[i]] || s[j] == s[i]) {
        if (s[j] == s[i])
          counter1++;
        else
          counter2++;
      } else
        break;
    }
    ans += min(counter1, counter2);
    i = j;
  }
  cout << ans << endl;
  return 0;
}
