#include <bits/stdc++.h>
using namespace std;
const int N = 524300;
const int maxn = 210004;
int pos[N];
namespace FFT {
struct comp {
  double r, i;
  comp(double _r = 0, double _i = 0) : r(_r), i(_i) {}
  comp operator+(const comp& x) { return comp(r + x.r, i + x.i); }
  comp operator-(const comp& x) { return comp(r - x.r, i - x.i); }
  comp operator*(const comp& x) {
    return comp(r * x.r - i * x.i, i * x.r + r * x.i);
  }
  comp conj() { return comp(r, -i); }
} A[N], B[N];
const double pi = acos(-1.0);
void FFT(comp a[], int n, int t) {
  for (int i = 1; i < n; ++i)
    if (pos[i] > i) swap(a[i], a[pos[i]]);
  for (int d = 0; (1 << d) < n; ++d) {
    int m = 1 << d, m2 = m << 1;
    double o = pi * 2 / m2 * t;
    comp _w(cos(o), sin(o));
    for (int i = 0; i < n; i += m2) {
      comp w(1, 0);
      for (int j = 0; j < m; ++j) {
        comp &A = a[i + j + m], &B = a[i + j], t = w * A;
        A = B - t;
        B = B + t;
        w = w * _w;
      }
    }
  }
  if (t == -1)
    for (int i = 0; i < n; ++i) a[i].r /= n;
}
void mul(int* a, int* b, int* c, int k) {
  int i, j;
  for (i = 0; i < k; ++i) A[i] = comp(a[i], b[i]);
  j = __builtin_ctz(k) - 1;
  for (int i = 0; i < k; ++i) {
    pos[i] = pos[i >> 1] >> 1 | ((i & 1) << j);
  }
  FFT(A, k, 1);
  for (int i = 0; i < k; ++i) {
    j = (k - i) & (k - 1);
    B[i] = (A[i] * A[i] - (A[j] * A[j]).conj()) * comp(0, -0.25);
  }
  FFT(B, k, -1);
  for (int i = 0; i < k; ++i) {
    if (B[i].r >= 0)
      c[i] = (int)(B[i].r + 0.5);
    else
      c[i] = (int)(B[i].r - 0.5);
  }
}
}  // namespace FFT
template <class T>
inline void scan_d(T& ret) {
  char c;
  ret = 0;
  while ((c = getchar()) < '0' || c > '9')
    ;
  while (c >= '0' && c <= '9') ret = ret * 10 + (c - '0'), c = getchar();
}
int belong[maxn];
int r[450], l[450];
short x[450][maxn];
char a[maxn], b[maxn];
int a1[maxn << 1], b1[maxn << 1], c1[maxn << 1];
int main() {
  scanf("%s%s", a, b);
  int m;
  cin >> m;
  int tot = 0;
  int n = strlen(a);
  int m1 = strlen(b);
  int blo = pow(n, 2.0 / 3);
  for (int i = 0; i < n; i++) {
    int p = i;
    ++tot;
    l[tot] = i;
    while (p < n && p - i <= blo) {
      belong[p] = tot;
      r[tot] = p;
      p++;
    }
    i = p - 1;
  }
  for (int i = 1; i <= tot; i++) {
    int p = 1;
    int w = r[i] - l[i] + 1;
    while (p <= m1) p = p * 2;
    for (int j = 0; j < p; j++) {
      if (l[i] + j <= r[i]) {
        if (a[l[i] + j] == '1')
          a1[j] = 1;
        else
          a1[j] = -1;
      } else
        a1[j] = 0;
      if (j < m1) {
        if (b[m1 - j - 1] == '1')
          b1[j] = 1;
        else
          b1[j] = -1;
      } else
        b1[j] = 0;
    }
    FFT::mul(a1, b1, c1, p);
    for (int j = w - 1; j < m1; j++) {
      int q = (w - c1[j]) / 2;
      x[i][j] = q;
    }
  }
  for (int i = 0; i < m; i++) {
    int a1, b1, len;
    scanf("%d%d%d", &a1, &b1, &len);
    int ans = 0;
    int x1 = belong[a1];
    int y = belong[a1 + len - 1];
    if (x1 + 1 >= y) {
      for (int j = a1; j < a1 + len; j++) {
        if (a[j] != b[j - a1 + b1]) ans++;
      }
    } else {
      for (int j = a1; j <= r[x1]; j++) {
        if (a[j] != b[j - a1 + b1]) ans++;
      }
      for (int j = x1 + 1; j <= y - 1; j++) {
        ans += x[j][m1 - (l[j] - a1 + b1) - 1];
      }
      for (int j = l[y]; j < a1 + len; j++) {
        if (a[j] != b[j - a1 + b1]) ans++;
      }
    }
    printf("%d\n", ans);
  }
}
