#include <bits/stdc++.h>
using namespace std;
char arr[30];
inline int tran(char c) { return c - 'a'; }
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  string s;
  cin >> s;
  for (int i = 0; i < 30; i++) arr[i] = '?';
  int k;
  cin >> k;
  for (int i = 0; i < k; i++) {
    string tem;
    cin >> tem;
    arr[tran(tem[0])] = tem[1];
    arr[tran(tem[1])] = tem[0];
  }
  int L = s.size();
  int ans = 0;
  for (int i = 0; i < L - 1; i++) {
    char now = s[i];
    int a = tran(now);
    if (arr[a] == '?') continue;
    char nxt = arr[a];
    int cnt1 = 1, cnt2 = 0;
    int w;
    for (w = i + 1; w < L && (s[w] == now || s[w] == nxt); w++)
      if (s[w] == now)
        cnt1++;
      else
        cnt2++;
    ans += min(cnt1, cnt2);
    i = w - 1;
  }
  cout << ans << endl;
  return 0;
}
