#include #include #include #include using namespace std; using i32 = int; using u32 = unsigned int; using i64 = long long; using u64 = unsigned long long; #define rep(i,n) for(int i=0; i<(int)(n); i++) i64 solve(i64 n, i64 a, i64 b){ return atcoder::floor_sum(n/b, a, b, n%b); } int main(){ int T; cin >> T; while(T --> 0){ i64 n,a,b; cin >> n >> a >> b; i64 ans = solve(n,a,1) + solve(n,1,b) - solve(n,a,b); cout << ans << '\n'; } return 0; } struct ios_do_not_sync{ ios_do_not_sync(){ std::ios::sync_with_stdio(false); std::cin.tie(nullptr); } } ios_do_not_sync_instance;