#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 74, OO = 0x3f3f3f3f;
class CHometask {
 public:
  void solve(istream& cin, ostream& cout) {
    string s;
    cin >> s;
    int k;
    cin >> k;
    int ans = 0;
    for (int p = 0; p < k; p++) {
      char c, c2;
      cin >> c >> c2;
      for (int i = 0; i < s.size(); i++) {
        if (s[i] == c || s[i] == c2) {
          int j, cnt = 0, cnt2 = 0;
          for (j = i; j < s.size(); j++) {
            if (s[j] == c)
              ++cnt;
            else if (s[j] == c2)
              ++cnt2;
            else
              break;
          }
          i = j;
          ans += min(cnt, cnt2);
        }
      }
    }
    cout << ans << '\n';
  }
};
int main() {
  ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
  CHometask solver;
  std::istream& in(std::cin);
  std::ostream& out(std::cout);
  solver.solve(in, out);
  return 0;
}
