#include <bits/stdc++.h>
using namespace std;
const int N = 2e5;
char a[N + 1], b[N + 1];
unsigned A[32][N + 31 >> 5];
unsigned B[32][N + 31 >> 5];
static __inline int pc(unsigned n) {
  int ret;
  __asm__("popcnt %0, %1" : "=r"(ret) : "r"(n));
  return ret;
}
int query(int p, int q, int len) {
  int i = 0, res = 0;
  int x = p >> 5, u = p & 31;
  int y = q >> 5, v = q & 31;
  while (i + 32 <= len) {
    res += pc(A[u][x] ^ B[v][y]);
    ++x;
    ++y;
    i += 32;
  }
  len -= i;
  res += pc((A[u][x] ^ B[v][y]) & ((1 << len) - 1));
  return res;
}
int main() {
  scanf("%s %s", a, b);
  int n = strlen(a);
  for (int i = 0; i < 32; ++i) {
    for (int j = 0; i + j < n; ++j) {
      if (a[i + j] == '1') A[i][j >> 5] |= (1 << (j & 31));
    }
  }
  n = strlen(b);
  for (int i = 0; i < 32; ++i) {
    for (int j = 0; i + j < n; ++j) {
      if (b[i + j] == '1') B[i][j >> 5] |= (1 << (j & 31));
    }
  }
  int t, p, q, len;
  scanf("%d", &t);
  while (t--) {
    scanf("%d %d %d", &p, &q, &len);
    printf("%d\n", query(p, q, len));
  }
  return 0;
}
