#include <bits/stdc++.h>
using namespace std;
int Fabs(int x) { return (x > 0 ? x : -x); }
inline bool EQ(double a, double b) { return fabs(a - b) < 1e-9; }
inline int ones(int n) {
  int res = 0;
  while (n && ++res) n -= n & (-n);
  return res;
}
inline int last_bit(int n) { return n & (-n); }
inline int most_bit(int n) {
  int r(0);
  while (n >>= 1) r++;
  return (1ll << r);
}
string bin(int n) {
  string r("");
  while (n) {
    r += (n & 1 ? "1" : "0");
    n >>= 1;
  }
  return r;
}
const int INF = 1 << 29;
map<char, char> MAP;
int fun(string second) {
  int nbr(0);
  char last = second[0];
  for (int i = 1; i < (int)second.size(); i++) {
    if (last == MAP[second[i]]) {
      nbr++;
      continue;
    } else {
      last = second[i];
    }
  }
  return nbr;
}
int main(void) {
  string second, p;
  cin >> second;
  p = second;
  reverse(p.begin(), p.end());
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    string x;
    cin >> x;
    MAP[x[0]] = x[1];
    MAP[x[1]] = x[0];
  }
  int ans = 0;
  int i = 0;
  n = (int)second.size();
  while (i < n) {
    if (!MAP.count(second[i])) {
      i++;
      continue;
    }
    char x = second[i];
    char y = MAP[second[i]];
    int a = 0, b = 0;
    while (i < n && (second[i] == x || second[i] == y)) {
      if (second[i] == x)
        a++;
      else
        b++;
      i++;
    }
    ans += min(a, b);
  }
  cout << ans << endl;
  return 0;
}
