#include <bits/stdc++.h>
uint8_t buffer[16 * 32768];
using namespace std;
const long long mod = 2184057LL;
unsigned long long a[64][(218 * 1000) / 64];
unsigned long long b[64][(218 * 1000) / 64];
char buf[512 * 1000];
uint8_t POPCOUNT_4bit[16] = {0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4};
uint32_t ssse3_popcount3(uint8_t* buffer, int chunks16) {
  static char MASK_4bit[16] = {0xf, 0xf, 0xf, 0xf, 0xf, 0xf, 0xf, 0xf,
                               0xf, 0xf, 0xf, 0xf, 0xf, 0xf, 0xf, 0xf};
  uint32_t result;
  __asm__ volatile("movdqu (%%eax), %%xmm7" : : "a"(POPCOUNT_4bit));
  __asm__ volatile("movdqu (%%eax), %%xmm6" : : "a"(MASK_4bit));
  __asm__ volatile("pxor    %%xmm5, %%xmm5" : :);
  result = 0;
  int k, n, i;
  i = 0;
  while (chunks16 > 0) {
    if (chunks16 > (7 * 4)) {
      k = (7 * 4);
      chunks16 -= (7 * 4);
    } else {
      k = chunks16;
      chunks16 = 0;
    }
    __asm__ volatile("pxor %xmm4, %xmm4");
    for (n = 0; n < k; n += 4) {
      __asm__ volatile(
          "movdqa   (%%eax), %%xmm0   \n"
          "movdqa    %%xmm0, %%xmm1   \n"
          "psrlw         $4, %%xmm1   \n"
          "pand      %%xmm6, %%xmm0   \n"
          "pand      %%xmm6, %%xmm1   \n"
          "movdqa    %%xmm7, %%xmm2   \n"
          "movdqa    %%xmm7, %%xmm3   \n"
          "pshufb    %%xmm0, %%xmm2   \n"
          "pshufb    %%xmm1, %%xmm3   \n"
          "paddb     %%xmm2, %%xmm4   \n"
          "paddb     %%xmm3, %%xmm4   \n"
          :
          : "a"(&buffer[i]));
      ;
      __asm__ volatile(
          "movdqa   (%%eax), %%xmm0   \n"
          "movdqa    %%xmm0, %%xmm1   \n"
          "psrlw         $4, %%xmm1   \n"
          "pand      %%xmm6, %%xmm0   \n"
          "pand      %%xmm6, %%xmm1   \n"
          "movdqa    %%xmm7, %%xmm2   \n"
          "movdqa    %%xmm7, %%xmm3   \n"
          "pshufb    %%xmm0, %%xmm2   \n"
          "pshufb    %%xmm1, %%xmm3   \n"
          "paddb     %%xmm2, %%xmm4   \n"
          "paddb     %%xmm3, %%xmm4   \n"
          :
          : "a"(&buffer[i + 1 * 16]));
      ;
      __asm__ volatile(
          "movdqa   (%%eax), %%xmm0   \n"
          "movdqa    %%xmm0, %%xmm1   \n"
          "psrlw         $4, %%xmm1   \n"
          "pand      %%xmm6, %%xmm0   \n"
          "pand      %%xmm6, %%xmm1   \n"
          "movdqa    %%xmm7, %%xmm2   \n"
          "movdqa    %%xmm7, %%xmm3   \n"
          "pshufb    %%xmm0, %%xmm2   \n"
          "pshufb    %%xmm1, %%xmm3   \n"
          "paddb     %%xmm2, %%xmm4   \n"
          "paddb     %%xmm3, %%xmm4   \n"
          :
          : "a"(&buffer[i + 2 * 16]));
      ;
      __asm__ volatile(
          "movdqa   (%%eax), %%xmm0   \n"
          "movdqa    %%xmm0, %%xmm1   \n"
          "psrlw         $4, %%xmm1   \n"
          "pand      %%xmm6, %%xmm0   \n"
          "pand      %%xmm6, %%xmm1   \n"
          "movdqa    %%xmm7, %%xmm2   \n"
          "movdqa    %%xmm7, %%xmm3   \n"
          "pshufb    %%xmm0, %%xmm2   \n"
          "pshufb    %%xmm1, %%xmm3   \n"
          "paddb     %%xmm2, %%xmm4   \n"
          "paddb     %%xmm3, %%xmm4   \n"
          :
          : "a"(&buffer[i + 3 * 16]));
      ;
      i += 4 * 16;
    }
    __asm__ volatile(
        "pxor   %xmm0, %xmm0        \n"
        "psadbw %xmm0, %xmm4        \n"
        "paddd  %xmm4, %xmm5        \n");
  }
  __asm__ volatile(
      "movhlps   %%xmm5, %%xmm0   \n"
      "paddd     %%xmm5, %%xmm0   \n"
      "movd      %%xmm0, %%eax    \n"
      : "=a"(result));
  return result;
}
int main() {
  string sa, sb;
  scanf("%s", buf);
  sa = string(buf);
  scanf("%s", buf);
  sb = string(buf);
  memset(a, 0, sizeof(a));
  memset(b, 0, sizeof(b));
  for (int shift = 0; shift < 64; ++shift) {
    for (int i = 0; shift + i < ((int)(sa).size()); ++i) {
      unsigned long long bit = ((unsigned long long)1)
                               << (unsigned long long)(i % 64);
      int bucket = i / 64;
      if (sa[i + shift] == '1') {
        a[shift][bucket] |= bit;
      }
    }
    for (int i = 0; shift + i < ((int)(sb).size()); ++i) {
      unsigned long long bit = ((unsigned long long)1)
                               << (unsigned long long)(i % 64);
      int bucket = i / 64;
      if (sb[i + shift] == '1') {
        b[shift][bucket] |= bit;
      }
    }
  }
  int m;
  scanf("%d", &m);
  int prevP1 = -1, prevP2 = -1, prevL = -1, prevRes = -1;
  for (int it = 0; it < m; ++it) {
    int p1, p2, l;
    scanf("%d%d%d", &p1, &p2, &l);
    if (p1 == prevP1 && p2 == prevP2 && l == prevL) {
      printf("%d\n", prevRes);
      continue;
    }
    prevP1 = p1;
    prevP2 = p2;
    prevL = l;
    int shift1 = p1 % 64;
    int shift2 = p2 % 64;
    int start1 = p1 / 64;
    int start2 = p2 / 64;
    int res = 0;
    unsigned long long* A = a[shift1];
    unsigned long long* B = b[shift1];
    A += start1;
    B += start2;
    int UP = l / 64 - 1;
    unsigned long long* buff = (unsigned long long*)buffer;
    for (int i = 0; i <= UP; ++i) {
      buff[i] = a[shift1][start1 + i] ^ b[shift2][start2 + i];
    }
    unsigned long long mask =
        (((unsigned long long)1) << (unsigned long long)(l % 64)) -
        (unsigned long long)1;
    buff[UP + 1] =
        ((a[shift1][start1 + l / 64] ^ b[shift2][start2 + l / 64]) & mask);
    for (int i = 0; i < 16; ++i) buff[UP + i + 2] = 0;
    res = ssse3_popcount3(buffer, l / (8 * 16) + 1);
    printf("%d\n", res);
    prevRes = res;
  }
  return 0;
}
