#include <bits/stdc++.h>
using namespace std;
unsigned a[32][200005 / 32], b[32][200005 / 32];
char sa[200005], sb[200005];
int p[200005], one[1 << 16];
int N, M, Q;
inline int Ask(const unsigned &x) {
  return one[x >> 16] + one[x & ((1 << 16) - 1)];
}
int main() {
  int i, j, ans;
  int x, y, len;
  scanf("%s", sa), scanf("%s", sb);
  N = strlen(sa), M = strlen(sb);
  for (i = 0; i < N; i++)
    for (j = 1, x = i % 32, y = i / 32; i + j - 1 < N && j <= 32; j++)
      a[x][y] = (a[x][y] | ((sa[i + j - 1] - '0') << j - 1));
  for (i = 0; i < M; i++)
    for (j = 1, x = i % 32, y = i / 32; i + j - 1 < M && j <= 32; j++)
      b[x][y] = (b[x][y] | ((sb[i + j - 1] - '0') << j - 1));
  for (i = 1; i < (1 << 16); i++) one[i] = one[i ^ (i & (-i))] + 1;
  scanf("%d", &Q);
  while (Q--) {
    ans = 0;
    scanf("%d %d %d", &x, &y, &len);
    unsigned *lt = a[x % 32], *rt = b[y % 32];
    lt += x / 32, rt += y / 32;
    while (len >= 32) ans += Ask((*lt++) ^ (*rt++)), len -= 32;
    if (len) ans += Ask((*lt ^ *rt) & ((1U << len) - 1));
    printf("%d\n", ans);
  }
  return 0;
}
