#include <bits/stdc++.h>
using namespace std;
template <typename C>
void ma(C &a, C b) {
  if (a < b) a = b;
}
template <typename C>
void mi(C &a, C b) {
  if (a > b) a = b;
}
char s[401001], w[401001];
const int bl = (1 << 15);
int q;
int wyn[401001];
vector<pair<int, pair<int, int> > > zap[401001];
long long t[(1 << 18) * 2], t2[(1 << 18) * 2], t3[(1 << 18) * 2],
    t4[(1 << 18) * 2];
const unsigned P = 2013265921;
const unsigned gen = 440564289;
long long power(long long a, int w) {
  long long ret = 1;
  while (w) {
    if (w & 1) {
      ret *= a;
      ret %= P;
    }
    w /= 2;
    a *= a;
    a %= P;
  }
  return ret;
}
void FFT(long long *a, long long *b, long long x, int n) {
  if (n == 1) {
    b[0] = a[0];
    return;
  }
  n >>= 1;
  long long *ar = new long long[n];
  long long *b1 = new long long[n];
  long long *b2 = new long long[n];
  for (int i = 0; i < n; i++) ar[i] = a[i * 2];
  FFT(ar, b1, x * x % P, n);
  for (int i = 0; i < n; i++) ar[i] = a[i * 2 + 1];
  FFT(ar, b2, x * x % P, n);
  delete[] ar;
  long long xi = 1;
  for (int i = 0; i < n; i++) {
    b[i] = (b1[i] + b2[i] * xi) % P;
    xi = xi * x % P;
  }
  for (int i = 0; i < n; i++) {
    b[i + n] = (b1[i] + b2[i] * xi) % P;
    xi = xi * x % P;
  }
  delete[] b1;
  delete[] b2;
  if (xi != 1) exit(1);
}
int m, nn;
unsigned ss[32][401001 / 32], ww[32][401001 / 32];
void prebrut() {
  int i = 0;
  while (s[i]) {
    if (s[i] == '1') {
      for (int j = 0; j < 32; j++) {
        if (i - j >= 0) ss[j][(i - j) >> 5] ^= 1 << ((i - j) & 31);
      }
    }
    i++;
  }
  i = 0;
  while (w[i]) {
    if (w[i] == '1') {
      for (int j = 0; j < 32; j++) {
        if (i - j >= 0) ww[j][(i - j) >> 5] ^= 1 << ((i - j) & 31);
      }
    }
    i++;
  }
}
int brut2(unsigned *s, unsigned *w, int il, int os) {
  int wyn = 0;
  for (int i = 0; i < il; i++) wyn += __builtin_popcount(s[i] ^ w[i]);
  wyn += __builtin_popcount((s[il] ^ w[il]) & ((1 << os) - 1));
  return wyn;
}
inline int brut(int a, int b, int il) {
  int wyn = 0;
  wyn += brut2(ss[a & 31] + (a >> 5), ww[b & 31] + (b >> 5), il >> 5, il & 31);
  return wyn;
}
int main() {
  scanf("%s%s", s, w);
  prebrut();
  scanf("%d", &q);
  for (int i = 0; i < q; i++) {
    int a, b, dl;
    scanf("%d", &a);
    scanf("%d", &b);
    scanf("%d", &dl);
    int dl2 = min((a + bl - 1) / bl * bl - a, dl);
    wyn[i] += 2 * brut(a, b, dl2);
    a += dl2;
    b += dl2;
    dl -= dl2;
    dl2 = dl % bl;
    wyn[i] += 2 * brut(a + dl - dl2, b + dl - dl2, dl2);
    dl -= dl2;
    if (dl) zap[a / bl].push_back(make_pair(i, make_pair(b, dl)));
  }
  m = 0;
  while (w[m]) m++;
  nn = 1;
  while (nn <= m + bl) nn *= 2;
  for (int i = 0; i < m; i++) t[i] = (w[m - 1 - i] == '1' ? 1 : P - 1);
  long long pom = power(gen, (1 << 27) / nn);
  FFT(t, t2, pom, nn);
  int n = 0;
  while (s[n]) n++;
  unsigned p1 = power(nn, P - 2), p2 = power(pom, nn - 1);
  for (int i = 0; i < n / bl; i++) {
    for (int j = 0; j < nn; j++) t3[j] = 0;
    for (int j = 0; j < bl; j++) t3[j] = (s[i * bl + j] == '1' ? P - 1 : 1);
    FFT(t3, t4, pom, nn);
    for (int j = 0; j < nn; j++) t4[j] = t2[j] * t4[j] % P * p1 % P;
    FFT(t4, t3, p2, nn);
    for (int j = 0; j < nn; j++) {
      t3[j] += bl;
      if (t3[j] >= P) t3[j] -= P;
    }
    for (int j = 0; j < zap[i].size(); j++) {
      int gd = m - zap[i][j].second.first - 1;
      wyn[zap[i][j].first] += t3[gd];
      zap[i][j].second.second -= bl;
      zap[i][j].second.first += bl;
      if (zap[i][j].second.second) zap[i + 1].push_back(zap[i][j]);
    }
    zap[i].clear();
  }
  for (int i = 0; i < q; i++) printf("%d\n", wyn[i] / 2);
}
