#include <bits/stdc++.h>
using namespace std;
pair<long long int, long long int> pl;
pair<int, int> pa[100010];
map<int, int> m, m2;
vector<int> v[405];
set<long long int> st;
int main() {
  string s;
  cin >> s;
  int k, ct = 0;
  cin >> k;
  for (int i = 0; i < k; ++i) {
    string t;
    cin >> t;
    int x = 0, y = 0;
    for (int j = 0; j < s.length() + 1; ++j) {
      if (s[j] == t[0])
        x++;
      else if (s[j] == t[1])
        y++;
      else {
        ct += min(x, y);
        x = y = 0;
      }
    }
  }
  cout << ct << endl;
}
