#include <bits/stdc++.h>
using namespace std;
const long long int mod = 1e9 + 7;
long long m, k, n, a[200005], red[200005] = {0}, edge[505][505];
set<char> st, st1, st2;
string s1 = "", s;
vector<long long> v[2000005], vnode[200005], v1, v2, v3;
vector<pair<long long, long long> > vv;
vector<pair<pair<long long, long long>, long long> > vvv;
priority_queue<long long> pq;
map<long long, long long> mp;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  long long i = 0, j = 0, z = 0, res = 0, q, ans = 0, mx = 0, nb = 0, nbmax = 0,
            nbs = 0, sm = 0, nb2 = 0, mm = 5e8, idx = 0, ok = 0, l, r,
            negatif = 0, positif = 0;
  long long x, y;
  set<char>::iterator it, it1, it2;
  char c;
  cin >> s;
  cin >> m;
  for (i = 0; i < m; i++) {
    cin >> s1;
    edge[s1[0] - 'a'][s1[1] - 'a'] = edge[s1[1] - 'a'][s1[0] - 'a'] = 1;
  }
  n = s.size();
  if (n == 1 || !m) return cout << "0", 0;
  red[s[0] - 'a']++;
  st.insert(s[0]);
  for (i = 1; i < n; i++) {
    it = st.begin();
    if (!st.size() || st.find(s[i]) != st.end() ||
        st.size() == 1 && edge[s[i] - 'a'][(*it) - 'a'] == 1) {
      st.insert(s[i]);
      red[s[i] - 'a']++;
    } else if (st.size() == 2 && st.find(s[i]) == st.end()) {
      mm = 5e9;
      for (it = st.begin(); it != st.end(); it++)
        mm = min(mm, red[(*it) - 'a']);
      res += mm;
      for (it = st.begin(); it != st.end(); it++) red[(*it) - 'a'] = 0;
      st.clear();
      st.insert(s[i]);
      red[s[i] - 'a']++;
    } else if (st.size() == 1) {
      red[(*it) - 'a'] = 0;
      st.erase(*it);
      st.insert(s[i]);
      red[s[i] - 'a']++;
    }
  }
  if (st.size() == 2) {
    mm = 5e9;
    for (it = st.begin(); it != st.end(); it++) mm = min(mm, red[(*it) - 'a']);
    res += mm;
    st.clear();
  }
  cout << res;
}
