#include <bits/stdc++.h>
using namespace std;
const int oo = 0x3f3f3f3f;
const long long ooo = 9223372036854775807ll;
const int _cnt = 1000 * 1000 + 7;
const int _p = 998244353;
const int N = 215005;
const double PI = acos(-1.0);
const double eps = 1e-9;
int o(int x) { return x % _p; }
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }
void file_put() {
  freopen("filename.in", "r", stdin);
  freopen("filename.out", "w", stdout);
}
void build(vector<int> &V, int *l, int *r) {
  V.clear();
  for (auto t = l; t != r; ++t) V.push_back(*t);
}
inline void build(vector<int> &V, char *l, char *r) {
  V.clear();
  for (auto t = (l); t <= (r); ++t) V.push_back(2 * (*t - '0') - 1);
}
char s[N], t[N];
int n, m, q, l, r, x, y, L, B, dp[235][N], cnt = 0;
vector<int> A, BB, C;
inline void Query(int l, int r, int x, int y) {
  int ans = 0;
  while (l <= r && l % B != 0) ans += (s[l] == t[x]), ++l, ++x;
  while (l <= r && (r + 1) % B != 0 && r != n - 1)
    ans += (s[r] == t[y]), --r, --y;
  ans %= _p;
  for (; l <= r; l += B, x += B) ans += dp[l / B][x], ans %= _p;
  printf("%d\n", ans);
}
int getlen(int k) {
  return (((k + 1) * B) < (n) ? ((k + 1) * B) : (n)) - k * B;
}
void norm(vector<int> &V) {
  for (auto &t : V) {
    t = (t + _p) % _p;
    if (t > 200000) t -= _p;
  }
}
struct TT {
  const static int N = 1 << 19;
  const double pi = acos(-1.0);
  struct vir {
    double a, b;
    vir(double r = 0.0, double i = 0.0) { a = r, b = i; }
    vir operator+(const vir &o) const { return vir(a + o.a, b + o.b); }
    vir operator-(const vir &o) const { return vir(a - o.a, b - o.b); }
    vir operator*(const vir &o) const {
      return vir(a * o.a - b * o.b, b * o.a + a * o.b);
    }
    vir operator*(const double &o) const { return vir(a * o, b * o); }
    vir operator!() const { return vir(a, -b); }
  } x[N | 1], y[N | 1], z[N | 1], w[N | 1];
  int K;
  void fft(vir x[], int k, int v) {
    for (int i = 0, j = 0; i < k; i++) {
      if (i > j) swap(x[i], x[j]);
      for (int l = k >> 1; (j ^= l) < l; l >>= 1)
        ;
    }
    w[0] = vir(1, 0);
    for (int i = 2; i <= k; i <<= 1) {
      vir g = vir(cos(2 * pi / i), (v ? -1 : 1) * sin(2 * pi / i));
      for (int j = (i >> 1); j >= 0; j -= 2) w[j] = w[j >> 1];
      for (int j = 1; j < i >> 1; j += 2) w[j] = w[j - 1] * g;
      for (int j = 0; j < k; j += i) {
        vir *a = x + j, *b = a + (i >> 1);
        for (int l = 0; l < i >> 1; l++) {
          vir o = b[l] * w[l];
          b[l] = a[l] - o;
          a[l] = a[l] + o;
        }
      }
    }
    if (v)
      for (int i = 0; i < k; i++) x[i] = vir(x[i].a / k, x[i].b / k);
  }
  void multiply(int *a, int *b, int na, int nb, vector<int> &C) {
    reverse(a, a + na);
    na--, nb--;
    for (K = 1; K <= na + nb >> 1; K <<= 1)
      ;
    for (auto i = (0); i <= (K - 1); ++i) x[i] = y[i] = vir(0, 0);
    for (int i = 0; i <= na; i++) (i & 1 ? x[i >> 1].b : x[i >> 1].a) = a[i];
    for (int i = 0; i <= nb; i++) (i & 1 ? y[i >> 1].b : y[i >> 1].a) = b[i];
    fft(x, K, 0);
    fft(y, K, 0);
    for (auto i = (0); i <= (K - 1); ++i) {
      int j = K - 1 & K - i;
      vir tmp = (i & K >> 1) ? vir(1, 0) - w[i ^ K >> 1] : w[i] + vir(1, 0);
      z[i] = (x[i] * y[i] * 4 - (x[i] - !x[j]) * (y[i] - !y[j]) * tmp) * 0.25;
    }
    fft(z, K, 1);
    C.resize(na + nb + 1);
    for (auto i = (0); i <= (na + nb); ++i)
      C[i] = i & 1 ? z[i >> 1].b + 0.1 : z[i >> 1].a + 0.1;
    for (auto i = (na); i <= (na + nb); ++i) C[i - na] = C[i];
    C.resize(nb + 1);
    reverse(a, a + na + 1);
  }
} TTT;
int main() {
  scanf("%s%s%d", s, t, &q), n = strlen(s), m = strlen(t);
  for (auto i = (0); i <= (m - 1); ++i) t[i] ^= 1;
  B = sqrt(n) + 0.5;
  B = 1000;
  cnt = (n - 1) / B + 1;
  build(BB, t, t + m);
  for (auto k = (0); k <= (cnt - 1); ++k) {
    build(A, s + k * B, s + (((k + 1) * B) < (n) ? ((k + 1) * B) : (n)) - 1);
    TTT.multiply((int *)A.data(), (int *)BB.data(), (int)A.size(),
                 (int)BB.size(), C);
    norm(C);
    for (auto i = (0); i <= (m - 1); ++i)
      dp[k][i] = (long long)(getlen(k) + C[i]) >> 1;
  }
  while (q--) {
    scanf("%d%d%d", &l, &x, &L), r = l + L - 1, y = x + L - 1;
    Query(l, r, x, y);
  }
  return 0;
}
