#include <bits/stdc++.h>
using namespace std;
const double Pi = acos(-1.0);
struct cpx {
  double r, i;
  cpx(double _r = 0.0, double _i = 0.0) { r = _r, i = _i; }
  cpx operator+(const cpx &b) { return cpx(r + b.r, i + b.i); }
  cpx operator-(const cpx &b) { return cpx(r - b.r, i - b.i); }
  cpx operator*(const cpx &b) {
    return cpx(r * b.r - i * b.i, r * b.i + i * b.r);
  }
};
void change(vector<cpx> &y) {
  int ln = y.size();
  for (int i = 1, j = ln >> 1; i < ln - 1; i++) {
    if (i < j) swap(y[i], y[j]);
    int k = ln >> 1;
    while (j >= k) {
      j -= k;
      k >>= 1;
    }
    j += k;
  }
}
void fft(vector<cpx> &y, int on) {
  change(y);
  int len = y.size();
  for (int m = 2; m <= len; m <<= 1) {
    cpx wm(cos(-on * 2 * Pi / m), sin(-on * 2 * Pi / m));
    for (int k = 0; k < len; k += m) {
      cpx w(1, 0);
      for (int j = 0; j < m / 2; j++) {
        cpx u = y[k + j];
        cpx t = w * y[k + j + m / 2];
        y[k + j] = u + t;
        y[k + j + m / 2] = u - t;
        w = w * wm;
      }
    }
  }
  if (on == -1)
    for (int i = 0; i < len; i++) y[i].r /= len;
}
void mult(vector<int> &a, vector<int> &b, vector<int> &sol) {
  int len = 1;
  int la = a.size();
  int lb = b.size();
  while (len < la + lb) len <<= 1;
  vector<cpx> x1(len);
  vector<cpx> x2(len);
  for (int i = 0; i < la; i++) x1[i] = cpx(a[i], 0);
  for (int i = la; i < len; i++) x1[i] = cpx(0, 0);
  for (int i = 0; i < lb; i++) x2[i] = cpx(b[i], 0);
  for (int i = lb; i < len; i++) x2[i] = cpx(0, 0);
  fft(x1, 1);
  fft(x2, 1);
  for (int i = 0; i < len; i++) x1[i] = x1[i] * x2[i];
  fft(x1, -1);
  sol.resize(len);
  for (int i = 0; i < len; i++) {
    sol[i] = round(x1[i].r);
  }
}
const int N = 200010;
int SQ;
int n, m;
char a[200010], b[200010];
vector<int> c[N];
int calc(int p1, int p2, int len) {
  int res = 0;
  for (int i = 0; i < len; i++)
    if (a[p1 + i] != b[p2 + i]) res++;
  return res;
}
int get(int x, int len) { return (len - x) / 2; }
int main() {
  scanf("%s", a);
  scanf("%s", b);
  n = strlen(a);
  m = strlen(b);
  vector<int> A;
  for (int i = 0; i < n; i++)
    if (a[i] == '1')
      A.push_back(1);
    else
      A.push_back(-1);
  SQ = 6000;
  for (int i = 0; i < m; i += SQ) {
    vector<int> B;
    for (int j = 0; j < SQ; j++) {
      if (j + i >= m) break;
      if (b[i + j] == '0')
        B.push_back(-1);
      else
        B.push_back(1);
    }
    reverse(B.begin(), B.end());
    mult(A, B, c[i / SQ]);
  }
  int q;
  scanf("%d", &q);
  while (q--) {
    int p1, p2, len;
    scanf("%d", &p1);
    scanf("%d", &p2);
    scanf("%d", &len);
    int st2 = p1 + SQ - 1 - p2;
    int to = p2 + len - 1;
    int S = 0, E = SQ - 1;
    S = (p2 / SQ) * SQ;
    E = S + SQ - 1;
    int res = 0;
    while (true) {
      if (S <= p2 && E >= to) {
        res = calc(p1, p2, len);
        break;
      } else if (S >= p2 && E <= to)
        res += get(c[S / SQ][st2 + S], SQ);
      else if (S > to)
        break;
      else if (S < p2 && E >= p2)
        res += calc(p1, p2, E - p2 + 1);
      else if (S <= to && E > to)
        res += calc(p1 + (S - p2), S, to - S + 1);
      S += SQ;
      E += SQ;
    }
    printf("%d\n", res);
  }
  return 0;
}
