#include <bits/stdc++.h>
using namespace std;
const int maxn = 1005;
const double eps = 1e-9;
inline int sgn(double x){return fabs(x) < eps ? 0 : (x < 0 ? -1 : 1);}
inline int cmp(double x, double y){return sgn(x - y);}
struct Point
{
double x;
double y;
};
typedef Point Vector;
Vector operator + (Vector a, Vector b){return (Vector){a.x + b.x, a.y + b.y};}
Vector operator - (Vector a, Vector b){return (Vector){a.x - b.x, a.y - b.y};}
Vector operator * (Vector a, double b){return (Vector){a.x * b, a.y * b};}
Vector operator / (Vector a, double b){return (Vector){a.x / b, a.y / b};}
double operator & (Vector a, Vector b){return a.x * b.x + a.y * b.y;}
double operator ^ (Vector a, Vector b){return a.x * b.y - a.y * b.x;}
double PointDistance(Point a, Point b){return sqrt((b - a) & (b - a));}
struct Line
{
Point Pa;
Point Pb;
};
typedef Line Segment;
double LineDistance(Line a, Segment b){return ((b.Pa - a.Pa) ^ (b.Pb - a.Pa)) / ((b.Pb - b.Pa) ^ (a.Pb - a.Pa)) * PointDistance(a.Pa, a.Pb);}
struct Status
{
double Length;
int Flag;
};
inline bool operator < (Status a, Status b){return sgn(b.Length - a.Length) > 0;}
inline bool InLine(double x, double y, double z){return sgn(x - z) * sgn(y - z) <= 0;}
inline bool InLine(Point P1, Point P2, Point P3){return InLine(P1.x, P2.x, P3.x) && InLine(P1.y, P2.y, P3.y);}
inline Point GetCrossPoint(Point P1, Point P2, Point P3, Point P4)
{
double W1 = (P1 - P3) ^ (P4 - P3), W2 = (P4 - P3) ^ (P2 - P3);
return (Point)((P1 * W2 + P2 * W1) / (W1 + W2));
}
inline bool check(Point P1, Point P2, Point P3, Point P4)
{
double W1 = (P3 - P1) ^ (P4 - P1), W2 = (P3 - P2) ^ (P4 - P2);
return sgn(W1 - W2) != 0;
}
signed main()
{
int n, m; scanf("%d %d", &n, &m);
Point A, B; scanf("%lf %lf %lf %lf", &A.x, &A.y, &B.x, &B.y);
vector<Point> P(n + 1);
for (int i = 1; i <= n; i ++) scanf("%lf %lf", &P[i].x, &P[i].y);
while (m --)
{
int u, v; cin >> u >> v;
vector<Point> ans;
for (int i = 1; i <= n; i ++)
{
if (i == u) continue;
if (check(P[u], P[i], A, B))
{
Point Cross = GetCrossPoint(P[u], P[i], A, B);
if (InLine(A, B, Cross)) ans.push_back(Cross);
}
}
if (A.x == B.x)
{
sort(ans.begin(), ans.end(), [&](Point P1, Point P2){return P1.y < P2.y;});
if (A.y > B.y) reverse(ans.begin(), ans.end());
}
else
{
sort(ans.begin(), ans.end(), [&](Point P1, Point P2){return P1.x < P2.x;});
if (A.x > B.x) reverse(ans.begin(), ans.end());
}
if (ans.size() >= v) printf("%.10lf %.10lf\n", ans[v - 1].x, ans[v - 1].y);
else printf("-1\n");
}
return 0;
}
#include <bits/stdc++.h>
using i64 = long long;
using Line = std::tuple<int, int, i64>;
using Point = std::tuple<int, int>;
struct P {
Line l;
Point p;
int c;
};
int main() {
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
int N;
std::cin >> N;
int X[N], Y[N], C[N];
for (int i = 0; i < N; i++) {
std::cin >> X[i] >> Y[i] >> C[i];
}
std::vector<P> v;
for (int i = 0; i < N; i++) {
for (int j = i + 1; j < N; j++) {
int dx = X[j] - X[i];
int dy = Y[j] - Y[i];
int g = std::gcd(dx, dy);
dx /= g;
dy /= g;
if (dx < 0) {
dx = -dx;
dy = -dy;
}
if (dx == 0 && dy < 0) {
dy = -dy;
}
v.push_back({Line(dx, dy, 1LL * dx * (X[i] + X[j]) + 1LL * dy * (Y[i] + Y[j]))
, Point(X[i] + X[j], Y[i] + Y[j]), C[i] + C[j]});
}
}
std::sort(v.begin(), v.end(), [&](auto a, auto b) {
if (a.l != b.l) {
return a.l < b.l;
} else if (a.p != b.p) {
return a.p < b.p;
} else {
return a.c > b.c;
}
});
i64 res = -1;
for (int i = 0, j; i < int(v.size()); i = j) {
for (j = i; j < int(v.size()) && v[i].l == v[j].l; j++)
;
i64 x[2];
x[0] = x[1] = -1E18;
for (int k = i; k < j; k++) {
if (k == i || v[k].p != v[k - 1].p) {
i64 y = v[k].c;
if (y > x[0]) {
x[1] = x[0];
x[0] = y;
} else if (y > x[1]) {
x[1] = y;
}
}
}
res = std::max(res, x[0] + x[1]);
}
std::cout << res << "\n";
return 0;
}