#include using namespace std; using ll = long long; int main(){ ios::sync_with_stdio(false); cin.tie(0); int q; cin >> q; constexpr ll inf = 1'000'000'000; while(q--){ ll a, b, x0, y0, x1, y1; cin >> a >> b >> x0 >> y0 >> x1 >> y1; ll xofs = (inf / a) * a, yofs = (inf / b) * b; x0 += xofs; x1 += xofs; y0 += yofs; y1 += yofs; x0 /= a, x1 /= a, y0 /= b, y1 /= b; cout << abs(x0 - x1) + abs(y0 - y1) << '\n'; } }