#include <bits/stdc++.h>
using namespace std;
const long long int INF = 1e18;
const int inf = 1e9;
const int MOD = 1e9 + 7;
const int nax = 1000000 + 10;
int n, arr[nax];
int dp[nax][28];
string s;
unordered_map<char, char> map1;
int solve(int cur, char last) {
  int l = last - (int)'a';
  if (cur == n) return 0;
  if (dp[cur][l] != -1) return dp[cur][l];
  char asli = map1[s[cur]];
  int ans;
  if (asli == last)
    ans = 1 + solve(cur + 1, last);
  else {
    ans = 1 + solve(cur + 1, last);
    ans = min(ans, solve(cur + 1, s[cur]));
  }
  return dp[cur][l] = ans;
}
int main() {
  ios::sync_with_stdio(0);
  for (int i = 'a'; i <= 'z'; i++) map1[i] = '#';
  cin >> s;
  n = s.length();
  int t;
  cin >> t;
  while (t--) {
    string s1;
    cin >> s1;
    map1[s1[0]] = s1[1];
    map1[s1[1]] = s1[0];
  }
  memset(dp, -1, sizeof(dp));
  cout << solve(0, 'z' + 1);
  return 0;
}
