#include <bits/stdc++.h>
using namespace std;
string str;
map<char, char> m;
map<char, long long int> val;
long long int n;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  string temp;
  long long int i, j, cnt = 0;
  char last = '1';
  cin >> str;
  cin >> j;
  n = str.size();
  for (i = 0; i < 26; i++) m[(char)('a' + i)] = '0';
  for (i = 0; i < j; i++) {
    cin >> temp;
    m[temp[0]] = temp[1];
    m[temp[1]] = temp[0];
  }
  for (i = 0; i < n; i++) {
    if ((last == str[i] or last == m[str[i]]) && m[last] != '0') {
      val[str[i]]++;
    } else {
      cnt += min(val[last], val[m[last]]);
      val[last] = 0;
      val[m[last]] = 0;
      last = str[i];
      val[str[i]] = 1;
    }
  }
  cnt += min(val[last], val[m[last]]);
  cout << cnt << '\n';
  return 0;
}
