#include <bits/stdc++.h>
#pragma warning(disable : 4244 4267 4018 4996 4800)
using namespace std;
istream &in = cin;
ostream &out = cout;
namespace fft {
map<int, vector<int>> revbits;
map<pair<int, bool>, vector<complex<double>>> w_pow_cache;
double const pi = acos(-1.);
void fft_impl(vector<complex<double>> &v, bool invert) {
  int n = v.size();
  vector<int> &rev = revbits[n];
  if (rev.empty()) {
    int logn = 0;
    while ((1 << logn) < n) ++logn;
    rev.resize(n);
    for (int i = 0; i < n; ++i) {
      for (int j = 0; j < logn; ++j)
        if (i & (1 << j)) rev[i] |= 1 << (logn - 1 - j);
    }
  }
  for (int i = 0; i < n; ++i) {
    if (i < rev[i]) swap(v[i], v[rev[i]]);
  }
  complex<double> *p = &v[0];
  for (int len = 2; len <= n; len <<= 1) {
    int len2 = len >> 1;
    vector<complex<double>> &w_pow = w_pow_cache[make_pair(len2, invert)];
    if (w_pow.empty()) {
      double ang = (invert ? -1 : 1) * 2 * pi / len;
      complex<double> w(cos(ang), sin(ang));
      w_pow.resize(len2);
      w_pow[0] = complex<double>(1, 0);
      for (int i = 1; i < len2; ++i) {
        w_pow[i] = w_pow[i - 1];
        w_pow[i] *= w;
      }
    }
    for (int i = 0; i < n; i += len) {
      complex<double> *pu = p + i, *pv = pu + len2, *pu_end = pv,
                      *pw = &w_pow[0];
      for (; pu != pu_end; ++pu, ++pv, ++pw) {
        complex<double> t = *pv;
        t *= *pw;
        *pv = *pu;
        *pv -= t;
        *pu += t;
      }
    }
  }
}
vector<double> fft(vector<double> const &p, vector<double> const &q) {
  int n = 1;
  for (; n < p.size() + q.size(); n <<= 1)
    ;
  vector<complex<double>> a(n), b(n);
  for (int i = 0; i < p.size(); ++i) a[i] = complex<double>(p[i]);
  for (int i = 0; i < q.size(); ++i) b[i] = complex<double>(q[i]);
  fft_impl(a, false);
  fft_impl(b, false);
  for (int i = 0; i < n; ++i) a[i] *= b[i];
  fft_impl(a, true);
  vector<double> res(n);
  for (int i = 0; i < n; ++i) res[i] = real(a[i]) / n;
  return res;
}
}  // namespace fft
vector<char> read_vec() {
  string s;
  in >> s;
  vector<char> res(s.size());
  for (int i = 0; i < res.size(); ++i) res[i] = s[i] - '0';
  return res;
}
void convert(vector<double> &v) {
  for (auto &x : v)
    if (x == 0) x = -1;
}
vector<char> randvec() {
  vector<char> res(200000);
  for (auto &x : res) x = rand() % 2;
  return res;
}
vector<unsigned long long> toint(vector<char> const &v) {
  vector<unsigned long long> res;
  if (v.size() < 64) return res;
  unsigned long long cur = 0;
  res.reserve(v.size() - 63);
  for (int i = 0; i < 64; ++i) cur = (cur << 1) | v[i];
  res.push_back(cur);
  for (int i = 64; i < v.size(); ++i) {
    cur = (cur << 1) | v[i];
    res.push_back(cur);
  }
  return res;
}
int bitcount(unsigned i) {
  i = i - ((i >> 1) & 0x55555555);
  i = (i & 0x33333333) + ((i >> 2) & 0x33333333);
  i = (i + (i >> 4)) & 0x0f0f0f0f;
  i = i + (i >> 8);
  i = i + (i >> 16);
  return i & 0x3f;
}
int main() {
  ios_base::sync_with_stdio(false);
  vector<char> a = read_vec(), b = read_vec();
  vector<double> bd(b.begin(), b.end());
  convert(bd);
  int block = 6900;
  vector<vector<double>> blockfft;
  vector<double> apart;
  vector<unsigned long long> ia = toint(a), ib = toint(b);
  for (int i = 0; i < a.size(); i += block) {
    int end = min<int>(a.size(), i + block);
    apart.assign(a.begin() + i, a.begin() + end);
    convert(apart);
    reverse((apart).begin(), (apart).end());
    blockfft.push_back(fft::fft(apart, bd));
  }
  int qnum;
  in >> qnum;
  unsigned long long mask32 = (1LL << 32) - 1;
  for (int q = 0; q < qnum; ++q) {
    int p1, p2, len, res = 0;
    in >> p1 >> p2 >> len;
    for (int idx = p1 / block;; ++idx) {
      int start = idx * block;
      int end = min<int>(a.size(), start + block);
      if (start >= p1 + len) break;
      if (start < p1 || end >= p1 + len) {
        int left1 = max(start, p1), right1 = min(end, p1 + len),
            left2 = p2 + left1 - p1;
        for (; left1 + 64 <= right1; left1 += 64, left2 += 64) {
          unsigned long long x = ia[left1] ^ ib[left2];
          res += bitcount(x >> 32) + bitcount(x & mask32);
        }
        for (; left1 < right1; ++left1, ++left2) res += a[left1] ^ b[left2];
      } else {
        res += (block - round(blockfft[idx][end - p1 - 1 + p2])) / 2;
      }
    }
    out << res << '\n';
  }
  return 0;
}
