#!/usr/bin/python3

import sys
import queue
import math

class AStar:
    def __init__(self, n, adj, cost, x, y):
        # See the explanations of these fields in the starter for friend_suggestion
        self.n = n
        self.adj = adj
        self.cost = cost
        self.inf = n*10**6
        self.d = [self.inf]*n
        self.visited = [False]*n
        self.workset = []
        self.potential={}
        # Coordinates of the nodes
        self.x = x
        self.y = y

    def clear(self):
        for v in self.workset:
            self.d[v] = self.inf
            self.visited[v] = False
        del self.workset[0:len(self.workset)]
        self.potential={}

    def potential_func(self,initial,final):
        if initial not in self.potential:
            x1=self.x[initial]
            y1=self.y[initial]
            x2=self.x[final]
            y2=self.y[final]
            res=math.sqrt((x1-x2)**2 + (y1-y2)**2)
            self.potential[initial]=res
            return res

    def extract(self,q):
        var,v=q.get()
        return v

    def visit(self, q, v, dist, measure):
        if (self.d[v] > dist):
            self.d[v] = dist
            self.workset.append(v)
            q.put((self.d[v] + measure, v))
        pass

    # Returns the distance from s to t in the graph
    def query(self, s, t):
        self.clear()
        q = queue.PriorityQueue()
        # Implement the rest of the algorithm yourself
        self.visit(q,s,0,self.potential_func(s,t))
        while(q.empty()==False):
            v=self.extract(q)
            if(v==t):
                if(self.d[t]!=self.inf):
                    return self.d[t]
                else:
                    return -1
            if(self.visited[v]==False):
                set=zip(adj[v],cost[v])
                for u,w in set:
                    if(self.visited[u]==False):
                        self.visit(q,u,self.d[v]+w,self.potential_func(u,t))
            self.visited[v]=True
        return -1

def readl():
    return map(int, sys.stdin.readline().split())

if __name__ == '__main__':
    n,m = readl()
    x = [0 for _ in range(n)]
    y = [0 for _ in range(n)]
    adj = [[] for _ in range(n)]
    cost = [[] for _ in range(n)]
    for i in range(n):
        a, b = readl()
        x[i] = a
        y[i] = b
    for e in range(m):
        u,v,c = readl()
        adj[u-1].append(v-1)
        cost[u-1].append(c)
    t, = readl()
    astar = AStar(n, adj, cost, x, y)
    for i in range(t):
        s, t = readl()
        print(astar.query(s-1, t-1))
