#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
int fx[] = {-1, +0, +1, +0, +1, +1, -1, -1, +0};
int fy[] = {+0, -1, +0, +1, +1, -1, +1, -1, +0};
int day[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
template <typename T>
inline bool isLeap(T y) {
  return (y % 400 == 0) || (y % 100 ? y % 4 == 0 : false);
}
template <typename T>
inline T GCD(T a, T b) {
  a = abs(a);
  b = abs(b);
  if (a < b) swap(a, b);
  while (b) {
    a = a % b;
    swap(a, b);
  }
  return a;
}
template <typename T>
inline T EGCD(T a, T b, T &x, T &y) {
  if (a == 0) {
    x = 0;
    y = 1;
    return b;
  }
  T x1, y1;
  T d = EGCD(b % a, a, x1, y1);
  x = y1 - (b / a) * x1;
  y = x1;
  return d;
}
template <typename T>
inline T LCM(T x, T y) {
  T tp = GCD(x, y);
  if ((x / tp) * 1. * y > 9e18) return 9e18;
  return (x / tp) * y;
}
template <typename T>
inline T BigMod(T A, T B, T M = MOD) {
  A %= M;
  T ret = 1;
  while (B) {
    if (B & 1) ret = (ret * A) % M;
    A = (A * A) % M;
    B = B >> 1;
  }
  return ret;
}
template <typename T>
inline T InvMod(T A, T M = MOD) {
  return BigMod(A, M - 2, M);
}
template <typename T>
void Compress(T *in, int n, int f = 0) {
  vector<T> vv;
  for (int i = f; i < n + f; i++) vv.push_back(in[i]);
  sort(vv.begin(), vv.end()), vv.erase(unique(vv.begin(), vv.end()), vv.end());
  for (int i = f; i < n + f; i++)
    in[i] = lower_bound(vv.begin(), vv.end(), in[i]) - vv.begin();
}
template <typename T>
T scani(T &n) {
  n = 0;
  bool negative = false;
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-') negative = true;
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    n = n * 10 + c - 48;
    c = getchar();
  }
  if (negative) n = ~(n - 1);
  return n;
}
template <typename T>
void write(T n, int type = true) {
  if (n < 0) {
    putchar('-');
    n = -n;
  }
  if (!n) {
    putchar('0');
    if (type == 32)
      putchar(' ');
    else if (type)
      putchar('\n');
    return;
  }
  char buff[22];
  int len = 0;
  while (n) buff[len++] = n % 10 + 48, n /= 10;
  for (int i = len - 1; i >= 0; i--) putchar(buff[i]);
  if (type == 32)
    putchar(' ');
  else if (type)
    putchar('\n');
}
int scans(char *a) {
  int i = 0;
  char c = 0;
  while (c < 33) c = getchar();
  while (c > 33) {
    a[i++] = c;
    c = getchar();
  }
  a[i] = 0;
  return i;
}
const int pSz = 2000006;
bool np[pSz + 10];
vector<int> prime;
int prime_size;
void sieve() {
  np[0] = np[1] = 1;
  prime.push_back(2);
  for (long long i = 4; i <= pSz; i += 2) np[i] = 1;
  for (long long i = 3; i <= pSz; i += 2) {
    if (!np[i]) {
      prime.push_back(i);
      for (long long j = i * i; j <= pSz; j += (i << 1)) np[j] = 1;
    }
  }
  prime_size = prime.size();
}
template <typename T>
inline T SqrDis(T x1, T y1, T x2, T y2) {
  return ((x1 - x2) * (x1 - x2)) + ((y1 - y2) * (y1 - y2));
}
template <typename T>
inline T Area2(T Ax, T Ay, T Bx, T By, T Cx, T Cy) {
  T ret = Ax * (By - Cy) + Bx * (Cy - Ay) + Cx * (Ay - By);
  if (ret < 0) return ret = -ret;
  return ret;
}
const int N = 200005;
const int M = 200005;
const unsigned long long hs = 3797;
struct complx {
  double real, img;
  inline complx() { real = img = 0.0; }
  inline complx(double x) { real = x, img = 0.0; }
  inline complx(double x, double y) { real = x, img = y; }
  inline void operator+=(complx &other) {
    real += other.real, img += other.img;
  }
  inline void operator-=(complx &other) {
    real -= other.real, img -= other.img;
  }
  inline complx operator+(complx &other) {
    return complx(real + other.real, img + other.img);
  }
  inline complx operator-(complx &other) {
    return complx(real - other.real, img - other.img);
  }
  inline complx operator*(complx &other) {
    return complx((real * other.real) - (img * other.img),
                  (real * other.img) + (img * other.real));
  }
};
complx wlen_P[1048625 >> 1], A[1048625], B[1048625];
void FFT(complx *ar, int n, int inv) {
  int i, j, l, len, len2;
  const double p = 4.0 * inv * acos(0.0);
  for (i = 1, j = 0; i < n; i++) {
    for (l = n >> 1; j >= l; l >>= 1) j -= l;
    j += l;
    if (i < j) swap(ar[i], ar[j]);
  }
  for (len = 2; len <= n; len <<= 1) {
    len2 = len >> 1;
    double theta = p / len;
    complx mul(cos(theta), sin(theta));
    wlen_P[0] = complx(1, 0);
    for (i = 1; i < len2; i++) wlen_P[i] = (wlen_P[i - 1] * mul);
    for (i = 0; i < n; i += len) {
      complx t, *pu = ar + i, *pv = ar + i + len2, *pend = ar + i + len2,
                *pw = wlen_P;
      for (; pu != pend; pu++, pv++, pw++) {
        t = (*pv) * (*pw);
        *pv = *pu - t;
        *pu += t;
      }
    }
  }
  if (inv == -1) {
    double tmp = 1.0 / n;
    for (i = 0; i < n; i++) ar[i].real *= tmp;
  }
}
const int base = 7000;
int box[150][N], len[222];
char a[N], b[N];
int na, nb, bit[(1 << 16) + 10];
unsigned long long Bta[N / 64], Btb[N];
void print(unsigned long long x) {
  string s;
  for (int i = (0); i < (64); ++i) {
    s += (x & 1) + '0';
    x /= 2;
  }
  reverse(s.begin(), s.end());
  cout << s << '\n';
}
void precal() {
  for (int i = 0; i < (1 << 16) + 1; i++) bit[i] = __builtin_popcount(i);
  for (int l = 0; l < na; l += 64) {
    int r = min(na - 1, l + 63);
    int bi = l / 64, ln = (r - l + 1);
    for (int i = 0; i < ln; i++) {
      if (a[i + l] == '0') continue;
      Bta[bi] |= (1ULL << (63 - i));
    }
  }
  for (int l = 0; l < nb; l++) {
    int r = min(nb - 1, l + 63);
    int ln = (r - l + 1);
    for (int i = 0; i < ln; i++) {
      if (b[i + l] == '0') continue;
      Btb[l] |= (1ULL << (63 - i));
    }
  }
}
int bitMatch(unsigned long long x, unsigned long long y) {
  int ret = 0;
  unsigned short tx, ty;
  for (int i = (0); i < (4); ++i) {
    tx = x;
    ty = y;
    ret += bit[tx ^ ty];
    x >>= 16;
    y >>= 16;
  }
  return ret;
}
int ans_me(int ai, int bi, int l) {
  int ret = 0;
  int x = ai;
  int y = (ai + l - 1);
  int ix = x / 64;
  int iy = y / 64;
  if (ix == iy) {
    for (int i = (0); i < (l); ++i) ret += (a[ai + i] != b[bi + i]);
  } else {
    for (int i = (0); i < ((ix + 1) * 64 - x); ++i)
      ret += (a[ai + i] != b[bi + i]);
    for (int i = (0); i < (y - iy * 64 + 1); ++i)
      ret += (a[(ai + l - 1) - i] != b[(bi + l - 1) - i]);
    for (int i = (ix + 1); i < (iy); ++i)
      ret += bitMatch(Bta[i], Btb[bi + (i * 64 - ai)]);
  }
  return ret;
}
int main() {
  na = scans(a);
  nb = scans(b);
  precal();
  int n = 1, sz = 0;
  while (n < nb + base) n = n << 1;
  for (int i = (0); i < (nb); ++i) B[n - 1 - i] = complx(b[i] == '1' ? 1 : -1);
  FFT(B, n, 1);
  for (int bi = (0); bi < (N); ++bi) {
    if (na < base || nb < base) break;
    int ix = bi * base;
    int iy = min(na, (bi + 1) * base) - 1;
    sz = bi;
    if (ix >= na) break;
    for (int i = (0); i < (n); ++i) A[i] = complx();
    int m = (iy - ix + 1);
    len[bi] = nb - m + 1;
    for (int i = (0); i < (m); ++i) A[i] = complx(a[ix + i] == '1' ? 1 : -1);
    FFT(A, n, 1);
    for (int i = (0); i < (n); ++i) A[i] = A[i] * B[i];
    FFT(A, n, -1);
    for (int i = (0); i < (nb - m + 1); ++i)
      box[bi][i] = (m - round(A[n - 1 - i].real)) / 2;
  }
  int qr;
  scani(qr);
  while (qr--) {
    int ai, bi, l;
    scani(ai), scani(bi), scani(l);
    int x = ai;
    int y = (ai + l - 1);
    int ix = x / base;
    int iy = y / base;
    int res = 0;
    if (ix == iy || l < base) {
      res += ans_me(ai, bi, l);
    } else {
      int m = y - iy * base + 1;
      res += ans_me(ai, bi, (ix + 1) * base - x);
      res += ans_me(ai + l - m, bi + l - m, m);
      for (int i = (ix + 1); i < (iy); ++i) res += box[i][bi + (i * base - ai)];
    }
    write(res);
  }
  return 0;
}
