#include #include using namespace std; using namespace atcoder; struct Fast { Fast() { std::cin.tie(nullptr); ios::sync_with_stdio(false); cout << setprecision(10); } } fast; #define rep(i, a, b) for (int(i) = (a); (i) < (int)(b); (i)++) using P = pair; using IP = pair; int main() { int q; cin >> q; while (q--) { int d, k; cin >> d >> k; if (d == 0) { if (k == 1) cout << "Yes\n0 0\n"; else cout << "No\n"; } else { if (k > 4 * d) { cout << "No\n"; } else { vector pts; rep(x, 0, d) { int y = d - x; int z = x * x + y * y; pts.push_back(IP(z, P(x, y))); pts.push_back(IP(z, P(-y, x))); pts.push_back(IP(z, P(-x, -y))); pts.push_back(IP(z, P(y, -x))); } sort(pts.begin(), pts.end()); auto p = pts[k - 1].second; cout << "Yes\n"; cout << p.first << " " << p.second << "\n"; } } } }