#include <bits/stdc++.h>
using namespace std;
template <class T>
inline void Read(T &x) {
  int f = 1;
  char t = getchar();
  while (t < '0' || t > '9') {
    if (t == '-') f = -1;
    t = getchar();
  }
  x = 0;
  while (t >= '0' && t <= '9') {
    x = x * 10 + t - '0';
    t = getchar();
  }
  x *= f;
}
template <class T>
inline void Write(T x) {
  static int q[35];
  int r = 0;
  do {
    q[++r] = x % 10;
    x /= 10;
  } while (x > 0);
  while (r > 0) putchar('0' + q[r--]);
  putchar('\n');
}
template <class T>
inline void chkmax(T &x, T y) {
  if (x < y) x = y;
}
template <class T>
inline void chkmin(T &x, T y) {
  if (x > y) x = y;
}
const int maxn = 340124;
const int maxl = 200005;
const int maxs = 110;
const double pi = acos(-1.0);
struct Complex {
  double x;
  double y;
  Complex() {}
  Complex(double x, double y) : x(x), y(y) {}
  inline Complex operator+(const Complex &rhs) {
    return Complex(x + rhs.x, y + rhs.y);
  }
  inline Complex operator-(const Complex &rhs) {
    return Complex(x - rhs.x, y - rhs.y);
  }
  inline Complex operator*(const Complex &rhs) {
    return Complex(x * rhs.x - y * rhs.y, x * rhs.y + y * rhs.x);
  }
};
int n;
int m;
char A[maxl];
char B[maxl];
bool flag;
void input() {
  scanf("%s", A + 1);
  scanf("%s", B + 1);
  n = strlen(A + 1);
  m = strlen(B + 1);
  for (int i = 1; i <= n; i++) A[i] -= '0';
  for (int i = 1; i <= m; i++) B[i] -= '0';
  if (n > m) {
    static char tmp[maxn];
    swap(n, m);
    memcpy(tmp, A, sizeof(A));
    memcpy(A, B, sizeof(A));
    memcpy(B, tmp, sizeof(B));
    flag = true;
  }
}
int blockn;
int block_sz;
int belong[maxl];
int belong2[maxl];
int diff[maxn][maxs];
int N;
int L;
int rev[maxn];
Complex bit[maxn];
void init(int len) {
  N = 1, L = 0;
  while (N < len) {
    N <<= 1;
    L++;
  }
  Complex d = Complex(sin(2 * pi / N), cos(2 * pi / N));
  bit[0] = Complex(1, 0);
  for (int i = 1; i <= N; i++) {
    bit[i] = bit[i - 1] * d;
  }
  for (int i = 0; i < N; i++) {
    rev[i] = rev[i >> 1] >> 1 | ((i & 1) << (L - 1));
  }
}
void dft(Complex *res, int flag) {
  Complex x, y;
  for (int i = 0; i < N; i++) {
    if (rev[i] > i) {
      swap(res[rev[i]], res[i]);
    }
  }
  for (int k = 1; k < N; k <<= 1) {
    for (int s = 0; s < N; s += (k << 1)) {
      for (int i = 0; i < k; i++) {
        x = res[s + i], y = res[s + k + i];
        if (flag == 1)
          y = y * bit[N / (k << 1) * i];
        else
          y = y * bit[N - N / (k << 1) * i];
        res[s + i] = x + y;
        res[s + k + i] = x - y;
      }
    }
  }
  if (flag == -1) {
    for (int i = 0; i < N; i++) {
      res[i].x /= N;
    }
  }
}
void getdiff(int s, int len, int idx) {
  static Complex a[maxn];
  static Complex b[maxn];
  static Complex c[maxn];
  for (int i = 0; i < len; i++) a[i].x = A[s + i] ? 1 : -1, a[i].y = 0;
  for (int i = len; i < N; i++) a[i].x = a[i].y = 0;
  for (int i = 0; i < m; i++) b[i].x = B[i + 1] ? 1 : -1, b[i].y = 0;
  for (int i = m; i < N; i++) b[i].x = b[i].y = 0;
  reverse(b, b + N);
  dft(a, 1);
  dft(b, 1);
  for (int i = 0; i < N; i++) c[i] = a[i] * b[i];
  dft(c, -1);
  for (int i = 1; i + len - 1 <= m; i++) {
    diff[i][idx] = len - ((int)(c[N - i].x + 0.5) + len) / 2;
  }
}
void prepare() {
  block_sz = sqrt(n * log2(n));
  if (m > 10000) {
    block_sz = (double)block_sz * 3;
  }
  chkmax(block_sz, 1);
  blockn = 1;
  for (int i = 1; i <= n; i++) {
    belong[i] = blockn;
    if (i % block_sz == 0 && i < n) blockn++;
  }
  init(m + block_sz);
  for (int i = 1; i <= blockn; i++) {
    int s = (i - 1) * block_sz + 1;
    int len = min(block_sz, n - s + 1);
    getdiff(s, len, belong[s]);
  }
}
int hamdist(int s1, int s2, int len) {
  int st;
  int ed;
  int cur = 1;
  int res = 0;
  if ((s1 - 1) % block_sz == 0)
    st = (s1 - 1) / block_sz + 1;
  else
    st = (s1 - 1) / block_sz + 2;
  if ((s1 + len - 1) % block_sz == 0)
    ed = ((s1 + len - 1) - 1) / block_sz + 1;
  else
    ed = ((s1 + len - 1) - 1) / block_sz;
  int stp = (st - 1) * block_sz + 1;
  while (cur <= len && s1 + cur - 1 < stp) {
    res += A[s1 + cur - 1] ^ B[s2 + cur - 1];
    cur++;
  }
  for (int i = st; i <= ed; i++) {
    res += diff[s2 + cur - 1][i];
    cur += block_sz;
  }
  while (cur <= len) {
    res += A[s1 + cur - 1] ^ B[s2 + cur - 1];
    cur++;
  }
  return res;
}
void solve() {
  int q;
  int len;
  int s1, s2;
  Read(q);
  while (q--) {
    Read(s1);
    Read(s2);
    Read(len);
    s1++;
    s2++;
    if (flag) swap(s1, s2);
    Write(hamdist(s1, s2, len));
  }
}
int main() {
  input();
  prepare();
  solve();
  return 0;
}
