#include <bits/stdc++.h>
using namespace std;
int IN() {
  int x = 0, ch;
  for (; (ch = getchar()) < '0' || ch > '9';)
    ;
  for (; ch >= '0' && ch <= '9'; (ch = getchar())) (x *= 10) += ch - '0';
  return x;
}
char s[200005];
int cnt[1 << 16];
unsigned int A[32][7005], B[32][7005];
int Num(unsigned int x) { return cnt[x >> 16] + cnt[x & ((1 << 16) - 1)]; }
int main() {
  scanf("%s", s);
  for (int i = 0; i < 32; i++)
    for (int j = 0; s[i + j]; j++)
      if (s[i + j] == '1') A[i][j >> 5] |= 1 << (j & 31);
  scanf("%s", s);
  for (int i = 0; i < 32; i++)
    for (int j = 0; s[i + j]; j++)
      if (s[i + j] == '1') B[i][j >> 5] |= 1 << (j & 31);
  for (int i = 1; i < 1 << 16; i++) cnt[i] = cnt[i >> 1] + (i & 1);
  for (int Q = IN(); Q--;) {
    int l = IN(), r = IN(), len = IN(), Ans = 0, i, j;
    for (i = l >> 5, j = r >> 5; len >= 32; len -= 32, i++, j++)
      Ans += Num(A[l & 31][i] ^ B[r & 31][j]);
    Ans += Num((A[l & 31][i] ^ B[r & 31][j]) & ((1 << len) - 1));
    printf("%d\n", Ans);
  }
}
