#include <bits/stdc++.h>
using namespace std;
void __print(int x) { cerr << x; }
void __print(long x) { cerr << x; }
void __print(long long x) { cerr << x; }
void __print(unsigned x) { cerr << x; }
void __print(unsigned long x) { cerr << x; }
void __print(unsigned long long x) { cerr << x; }
void __print(float x) { cerr << x; }
void __print(double x) { cerr << x; }
void __print(long double x) { cerr << x; }
void __print(char x) { cerr << '\'' << x << '\''; }
void __print(const char *x) { cerr << '\"' << x << '\"'; }
void __print(const string &x) { cerr << '\"' << x << '\"'; }
void __print(bool x) { cerr << (x ? "true" : "false"); }
template <typename T, typename V>
void __print(const pair<T, V> &x) {
  cerr << '{';
  __print(x.first);
  cerr << ',';
  __print(x.second);
  cerr << '}';
}
template <typename T>
void __print(vector<vector<T>> x) {
  cerr << "\n{";
  int f = x.size();
  for (int i = 0; i < f; i++) {
    cerr << "(";
    int g = x[i].size();
    for (auto j : x[i]) {
      cerr << j;
      (--g != 0) ? cerr << "," : cerr << "";
    }
    cerr << ")\n";
  }
  cerr << "}";
}
template <typename T>
void __print(const T &x) {
  int f = 0;
  cerr << '{';
  for (auto &i : x) cerr << (f++ ? "," : ""), __print(i);
  cerr << "}";
}
void __print(vector<bool> x) {
  cerr << "{";
  int f = x.size();
  for (auto i : x) {
    cerr << i;
    (--f != 0) ? cerr << "," : cerr << "";
  }
  cerr << "}";
}
void _print() { cerr << "]\n"; }
template <typename T, typename... V>
void _print(T t, V... v) {
  __print(t);
  if (sizeof...(v)) cerr << ", ";
  _print(v...);
}
template <typename... T>
void read(T &...args) {
  ((cin >> args), ...);
}
template <typename... T>
void writ(T &&...args) {
  ((cout << args << " "), ...);
}
void solve() {
  string s;
  cin >> s;
  int q;
  cin >> q;
  vector<char> mp(256, '.');
  for (int i = 0; i < q; i++) {
    string t;
    cin >> t;
    mp[t[0]] = t[1];
    mp[t[1]] = t[0];
  }
  char curr = '#';
  int _1 = 0, _2 = 0;
  s = s + '+';
  int ans = 0;
  for (int i = 0; i < (int)s.length(); i++) {
    if (mp[s[i]] == '.') {
      ans += min(_1, _2);
      _1 = 0, _2 = 0;
      curr = '#';
    } else if (s[i] != curr && mp[s[i]] != curr) {
      ans += min(_1, _2);
      _1 = 1, _2 = 0;
      curr = s[i];
    } else {
      ;
      if (curr == '#') curr = s[i];
      if (curr == s[i])
        _1++;
      else if (mp[curr] == s[i])
        _2++;
    }
  }
  cout << ans << endl;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  solve();
  return 0;
}
