#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(const T &x) {
  int f = 0;
  cerr << '{';
  for (auto &i : x) cerr << (f++ ? "," : ""), __print(i);
  cerr << "}";
}
void _print() { cerr << "]\n"; }
template <typename T, typename... V>
void _print(T t, V... v) {
  __print(t);
  if (sizeof...(v)) cerr << ", ";
  _print(v...);
}
int mulmd(long long a, long long b) {
  long long ret = (a * b) % 1000000007;
  return (int)ret;
}
inline int power(long long x, long long y, int p) {
  long long res = 1;
  x = x % p;
  while (y > 0) {
    if (y & 1) res = mulmd(res, x);
    y = y >> 1;
    x = mulmd(x, x);
  }
  return (int)res;
}
int submd(long long a, long long b) {
  long long ret = a - b;
  if (ret < 0) {
    ret += 1000000007;
  }
  return (int)ret;
}
int addmd(long long a, long long b) {
  long long ret = (a + b) % 1000000007;
  return (int)ret;
}
int invPow(long long a) { return power(a, 1000000007 - 2, 1000000007); }
const int N = 1e5 + 5;
int arr[N];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  string s;
  cin >> s;
  int k;
  cin >> k;
  vector<string> a(k);
  for (int i = 0; i < k; i++) {
    cin >> a[i];
  }
  int ans = 0;
  for (int i = 0; i < s.size() - 1; i++) {
    for (int j = 0; j < k; j++) {
      if ((s[i] == a[j][0] && s[i + 1] == a[j][1]) ||
          (s[i] == a[j][1] && s[i + 1] == a[j][0])) {
        int r = i;
        while (r >= 0 && (s[r] == s[i] || s[r] == s[i + 1])) {
          r--;
        }
        r += 1;
        string temp = "";
        int cnt1 = 0, cnt2 = 0;
        int l = -1;
        for (int t = r; t < s.size(); t++) {
          if (s[t] == s[i] || s[t] == s[i + 1]) {
            temp += s[t];
            if (s[t] == s[i])
              cnt1++;
            else
              cnt2++;
          } else {
            l = t;
            break;
          }
        }
        if (l == -1) l = s.size();
        ans += min(cnt1, cnt2);
        i = l - 1;
        break;
      }
    }
  }
  cout << ans;
}
