#include <bits/stdc++.h>
using namespace std;
const long long int inf = 9e18;
const long double pi = 2 * acos(0.0);
string str;
long long int cnt[26];
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  for (long long int i = 0; i < 26; ++i) cnt[i] = -1;
  long long int m;
  cin >> str;
  cin >> m;
  for (long long int i = 0; i < m; ++i) {
    string second;
    cin >> second;
    cnt[second[0] - 97] = second[1] - 97;
    cnt[second[1] - 97] = second[0] - 97;
  }
  long long int l = 0, r = 0, ans = 0, n = (int)((str).size());
  while (l < n) {
    if (cnt[str[l] - 97] != -1) {
      r = l;
      long long int a = str[l] - 97, b = cnt[str[l] - 97], k1 = 0, k2 = 0;
      while (r < n) {
        if (str[r] - 97 == a || str[r] - 97 == b) {
          if (str[r] - 97 == a)
            k1++;
          else
            k2++;
          r++;
        } else
          break;
      }
      ans += min(k1, k2);
      l = r;
    } else
      l++;
  }
  cout << ans << "\n";
}
