#include <bits/stdc++.h>
#pragma warning(disable : 4244 4267 4018 4996 4800)
using namespace std;
istream &in = cin;
ostream &out = cout;
namespace fft {
struct cd {
  cd(float real = 0, float imag = 0) : real(real), imag(imag) {}
  cd &operator+=(cd const &rhs) {
    real += rhs.real;
    imag += rhs.imag;
    return *this;
  }
  cd &operator*=(cd const &rhs) {
    float r = real * rhs.real - imag * rhs.imag;
    imag = real * rhs.imag + imag * rhs.real;
    real = r;
    return *this;
  }
  float real, imag;
};
cd operator*(cd const &lhs, cd const &rhs) {
  return cd(lhs.real * rhs.real - lhs.imag * rhs.imag,
            lhs.real * rhs.imag + lhs.imag * rhs.real);
}
cd operator-(cd const &lhs, cd const &rhs) {
  return cd(lhs.real - rhs.real, lhs.imag - rhs.imag);
}
float real(cd const &r) { return r.real; }
map<int, vector<int>> revbits;
float const pi = acos(-1.);
void fft_impl(vector<cd> &v, bool invert) {
  int n = v.size();
  cd *p = &v[0];
  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(p[i], p[rev[i]]);
  }
  vector<cd> w_pow(2 * n);
  for (int len = 2; len <= n; len <<= 1) {
    float ang = (invert ? -1 : 1) * 2 * pi / len;
    cd w(cos(ang), sin(ang));
    int len2 = len >> 1;
    w_pow[0] = cd(1, 0);
    for (int i = 1; i < len2; ++i) w_pow[i] = w_pow[i - 1] * w;
    for (int i = 0; i < n; i += len) {
      cd t, *pu = p + i, *pv = p + i + len2, *pu_end = p + i + len2,
            *pw = &w_pow[0];
      for (; pu != pu_end; ++pu, ++pv, ++pw) {
        t = *pv * *pw;
        *pv = *pu - 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<cd> a(n), b(n);
  for (int i = 0; i < p.size(); ++i) a[i] = cd(p[i]);
  for (int i = 0; i < q.size(); ++i) b[i] = cd(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;
}
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 = max<int>(1, a.size() / 50);
  vector<vector<double>> blockfft;
  vector<double> apart;
  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;
  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 left = max(start, p1);
        int right = min(end, p1 + len);
        char *pa = &a[left];
        char *pb = &b[left - p1 + p2];
        for (int k = left; k < right; ++k) res += *pa++ != *pb++;
      } else {
        res += int((block - blockfft[idx][end - p1 - 1 + p2]) / 2 + 0.5);
      }
    }
    out << res << '\n';
  }
  return 0;
}
