#include <bits/stdc++.h>
using namespace std;
const int maxlen = 200010;
unsigned int a[33][maxlen];
unsigned int b[33][maxlen];
int LUT[1 << 16];
int bits(unsigned int x) { return LUT[x & ((1 << 16) - 1)] + LUT[x >> 16]; }
int main() {
  for (int i = 0; i < (1 << 16); ++i) LUT[i] = LUT[i >> 1] + (i & 1);
  string s1;
  cin >> s1;
  string s2;
  cin >> s2;
  for (int i = 0; i < 32; ++i)
    for (int j = 0; j + i < s1.size(); ++j)
      if (s1[j + i] == '1') a[i][j >> 5] |= (1 << (j & 31));
  for (int i = 0; i < 32; ++i)
    for (int j = 0; j + i < s2.size(); ++j)
      if (s2[j + i] == '1') b[i][j >> 5] |= (1 << (j & 31));
  int q;
  scanf("%d", &q);
  for (int iter = 0; iter < q; ++iter) {
    int p1, p2, len;
    scanf("%d%d%d", &p1, &p2, &len);
    int sh1 = p1 & 31;
    int sh2 = p2 & 31;
    int ans = 0;
    int i;
    for (i = 0; i + 32 < len; i += 32) {
      ans += bits(a[sh1][(p1 - sh1 + i) >> 5] ^ b[sh2][(p2 - sh2 + i) >> 5]);
    }
    while (i < len) {
      ans += s1[p1 + i] != s2[p2 + i];
      ++i;
    }
    printf("%d\n", ans);
  }
  return 0;
}
