#include <bits/stdc++.h>
using namespace std;
const int N = 2e5;
short a[400][N];
string s1, s2;
unsigned long long pr1[N], pr2[N];
int main() {
  getline(cin, s1);
  getline(cin, s2);
  int n = s1.length();
  int m = s2.length();
  if (n > 64 && m > 64) {
    unsigned long long tmp = 0;
    for (int i = 0; i < 64; i++) {
      tmp <<= 1;
      tmp |= (s1[i] - '0');
    }
    pr1[0] = tmp;
    for (int i = 1; i <= n - 64; i++) {
      pr1[i] = ((pr1[i - 1] << 1) | (s1[i + 63] - '0'));
    }
    tmp = 0;
    for (int i = 0; i < 64; i++) {
      tmp <<= 1;
      tmp = tmp | (s2[i] - '0');
    }
    pr2[0] = tmp;
    for (int i = 1; i <= m - 64; i++) {
      pr2[i] = ((pr2[i - 1] << 1) | (s2[i + 63] - '0'));
    }
    for (int i = 0; i < n / 512; i++) {
      int l = i * 512;
      for (int j = 0; j <= m - 512; j++)
        a[i][j] = __builtin_popcountll(pr1[l] ^ pr2[j]) +
                  __builtin_popcountll(pr1[l + 64] ^ pr2[j + 64]) +
                  __builtin_popcountll(pr1[l + 128] ^ pr2[j + 128]) +
                  __builtin_popcountll(pr1[l + 192] ^ pr2[j + 192]) +
                  __builtin_popcountll(pr1[l + 256] ^ pr2[j + 256]) +
                  __builtin_popcountll(pr1[l + 320] ^ pr2[j + 320]) +
                  __builtin_popcountll(pr1[l + 384] ^ pr2[j + 384]) +
                  __builtin_popcountll(pr1[l + 448] ^ pr2[j + 448]);
    }
  }
  int q;
  scanf("%d", &q);
  for (int i = 0; i < q; i++) {
    int p1, p2, len;
    scanf("%d%d%d", &p1, &p2, &len);
    int ans = 0;
    while (p1 % 512 != 0 && len > 0) {
      if (s1[p1] != s2[p2]) ans++;
      p1++, p2++, len--;
    }
    int t = p1 / 512;
    while (len >= 512) {
      ans += a[t][p2];
      len -= 512;
      t++;
      p1 += 512;
      p2 += 512;
    }
    while (len > 0) {
      if (s1[p1] != s2[p2]) ans++;
      p1++, p2++, len--;
    }
    printf("%d\n", ans);
  }
  return 0;
}
