#include <bits/stdc++.h>
using namespace std;
unsigned long long firstnext64[64][3150];
unsigned long long secondnext64[64][3150];
char a[200005];
char b[200005];
int firstbits[200105];
int secondbits[200105];
int cnt[65536];
int main() {
  for (int g = 0; g < (1 << 16); g++) cnt[g] = __builtin_popcount(g);
  scanf("%s", a);
  scanf("%s", b);
  int lengA = strlen(a), lengB = strlen(b);
  for (int g = 0; g < lengA; g++) firstbits[g] = a[g] - '0';
  for (int g = 0; g < lengB; g++) secondbits[g] = b[g] - '0';
  for (int g = lengA - 1; g >= 0; g--) {
    firstnext64[g & 63][g >> 6] =
        firstbits[g] + (firstnext64[(g + 1) & 63][(g + 1) >> 6] << 1);
  }
  for (int g = lengB - 1; g >= 0; g--) {
    secondnext64[g & 63][g >> 6] =
        secondbits[g] + ((secondnext64[(g + 1) & 63][(g + 1) >> 6] << 1));
  }
  int Q;
  scanf("%d", &Q);
  for (int g = 0; g < Q; g++) {
    int l, r, leng;
    scanf("%d %d %d", &l, &r, &leng);
    int answer = 0;
    int m = l & 63, mm = r & 63;
    int loop = leng >> 6;
    for (int z = 0; z < loop; z++) {
      int y = 64 * z;
      unsigned long long t =
          firstnext64[m][(l + y) >> 6] ^ secondnext64[mm][(r + y) >> 6];
      answer += cnt[t & 0xFFFF] + cnt[(t >> 16) & 0xFFFF] +
                cnt[(t >> 32) & 0xFFFF] + cnt[(t >> 48)];
    }
    for (int z = leng - (leng & 63); z < leng; z++) {
      answer += firstbits[l + z] ^ secondbits[r + z];
    }
    printf("%d\n", answer);
  }
  return 0;
}
