The postal system in the area where Masa lives has changed a bit. In this area, each post office is numbered consecutively from 1 to a different number, and mail delivered to a post office is intended from that post office via several post offices. Delivered to the post office. Mail "forwarding" is only done between specific post offices. However, the transfer is bidirectional between the post offices where the transfer is performed.

If there are multiple routes for forwarding mail from a post office to the destination, use the route that minimizes the distance to the destination. Therefore, the forwarding destination will be the next post office on such a shortest path. If there are multiple routes with the shortest total distance, the postal office number that is the direct transfer destination is transferred to the younger one.

<image> <image>

By the way, the region is suffering from a serious labor shortage, and each post office has only one transfer person to transfer between post offices. They are doing their best to go back and forth. Of course, if the forwarding agent belonging to a post office has paid the mail when the mail arrives at that post office, the forwarding from that post office will be temporarily stopped.

When they are at their post office, they depart immediately if there is mail that has not been forwarded from that post office, and return immediately after delivering it to the forwarding destination. When he returns from the destination post office, he will not carry the mail that will be forwarded to his post office, even if it is at that post office (the mail will be forwarded to that mail). It is the job of the post office transferman).

If multiple mail items are collected at the time of forwarding, the mail that was delivered to the post office earliest is transferred first. Here, if there are multiple mail items that arrived at the same time, the mail is forwarded from the one with the youngest post office number that is the direct forwarding destination. If there is mail that has the same forwarding destination, it will also be forwarded together. Also, if the mail that should be forwarded to the same post office arrives at the same time as the forwarding agent's departure time, it will also be forwarded. It should be noted that they all take 1 time to travel a distance of 1.

You will be given information about the transfer between post offices and a list of the times when the mail arrived at each post office. At this time, simulate the movement of the mail and report the time when each mail arrived at the destination post office. It can be assumed that all the times required during the simulation of the problem are in the range 0 or more and less than 231.



Input

The input consists of multiple datasets, and the end of the input is represented by a single line with only 0 0. The format of each dataset is as follows.

The first line of the dataset is given the integers n (2 <= n <= 32) and m (1 <= m <= 496), separated by a single character space. n represents the total number of post offices and m represents the number of direct forwarding routes between post offices. There can never be more than one direct forwarding route between two post offices.

On the next m line, three integers containing information on the direct transfer route between stations are written. The first and second are the postal numbers (1 or more and n or less) at both ends of the transfer route, and the last integer represents the distance between the two stations. The distance is greater than or equal to 1 and less than 10000.

The next line contains the integer l (1 <= l <= 1000), which represents the number of mail items to process, followed by the l line, which contains the details of each piece of mail. Three integers are written at the beginning of each line. These are, in order, the sender's postal office number, the destination postal office number, and the time of arrival at the sender's postal office. At the end of the line, a string representing the label of the mail is written. This label must be between 1 and 50 characters in length and consists only of letters, numbers, hyphens ('-'), and underscores ('_'). Information on each of these mail items is written in chronological order of arrival at the post office of the sender. At the same time, the order is not specified. In addition, there is no mail with the same label, mail with the same origin and destination, or mail without a delivery route.

Each number or string in the input line is separated by a single character space.

Output

Output l lines for each dataset. Each output follows the format below.

For each mail, the time when the mail arrived is output on one line. On that line, first print the label of the mail, then with a one-character space, and finally print the time when the mail arrived at the destination post office. These are output in order of arrival time. If there are multiple mails arriving at the same time, the ASCII code of the label is output in ascending order.

A blank line is inserted between the outputs corresponding to each dataset.

Example

Input

4 5
1 2 10
1 3 15
2 3 5
2 4 3
3 4 10
2
1 4 10 LoveLetter
2 3 20 Greetings
3 3
1 2 1
2 3 1
3 1 1
3
1 2 1 BusinessMailC
2 3 1 BusinessMailB
3 1 1 BusinessMailA
0 0


Output

Greetings 25
LoveLetter 33

BusinessMailA 2
BusinessMailB 2
BusinessMailC 2
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
import java.util.PriorityQueue;
import java.util.Scanner;

//Poor Mail Forwarding
public class Main{

	final int SEND = 0, BACK = 1, INFORM = 2;
	int INF = 1<<29;
	int[][] e, next;
	boolean[] exist;
	int[] from, to;
	String[] letter;
	LinkedList<P>[] post;
	
	class T{
		int from;
		List<Integer> list;
		public T(int from) {
			this.from = from;
			list = new ArrayList<Integer>();
		}
	}
	class P implements Comparable<P>{
		int at, id, t;
		public P(int at, int id, int t) {
			this.at = at;
			this.id = id;
			this.t = t;
		}
		public int compareTo(P o) {
			return t!=o.t?t-o.t:next[at][to[id]]-next[at][to[o.id]];
		}
		@Override
		public String toString() {
			String r = "";
			r+="Pos:"+at+" Letter id:"+id+" Time:"+t;
			return r;
		}
	}
	class E implements Comparable<E>{
		int type, data, t;
		T con;
		public E(int type, int data, int t, T c) {
			this.type = type;
			this.data = data;
			this.t = t;
			con = c;
		}
		public int compareTo(E o) {
			return t!=o.t?t-o.t:type-o.type;
		}
		@Override
		public String toString() {
			String r = "";
			r+=type==BACK?"BACK":type==SEND?"SEND":"INFORM";
			r+=" at:"+data+" time:"+t;
			return r;
		}
	}
	class R implements Comparable<R>{
		String s;
		int t;
		public R(String s, int t) {
			this.s = s;
			this.t = t;
		}
		public int compareTo(R o) {
			return t!=o.t?t-o.t:s.compareTo(o.s);
		}
	}
	
	@SuppressWarnings("unchecked")
	void run(){
		Scanner sc = new Scanner(System.in);
		boolean head = true;
		for(;;){
			int n = sc.nextInt(), m = sc.nextInt();
			if((n|m)==0)break;
			if(!head)System.out.println();
			head = false;
			e = new int[n][n];
			int[][] adj = new int[n][n];
			for(int[]a:e)Arrays.fill(a, INF);
			for(int[]a:adj)Arrays.fill(a, INF);
			while(m--!=0){
				int s = sc.nextInt()-1, t = sc.nextInt()-1, d = sc.nextInt();
				e[s][t] = e[t][s] = d;
				adj[s][t] = adj[t][s] = d;
			}
			for(int i=0;i<n;i++)e[i][i]=0;
			for(int k=0;k<n;k++)for(int i=0;i<n;i++)for(int j=0;j<n;j++)e[i][j]=Math.min(e[i][j], e[i][k]+e[k][j]);
			next = new int[n][n];
			for(int i=0;i<n;i++)for(int j=0;j<n;j++){
				if(i==j||e[i][j]==INF)continue;
				for(int k=0;k<n;k++){
					if(i==k||adj[i][k]==INF)continue;
					if(e[i][j]==adj[i][k]+e[k][j]){
						next[i][j] = k; break;
					}
				}
			}
			PriorityQueue<R> res = new PriorityQueue<R>();
			exist = new boolean[n];
			Arrays.fill(exist, true);
			PriorityQueue<E> q = new PriorityQueue<E>();
			int L = sc.nextInt();
			from = new int[L]; to = new int[L]; letter = new String[L];
			post = new LinkedList[n];
			for(int i=0;i<n;i++)post[i] = new LinkedList<P>();
			for(int i=0;i<L;i++){
				from[i] = sc.nextInt()-1; to[i] = sc.nextInt()-1;
				int time = sc.nextInt();
				letter[i] = sc.next();
				post[from[i]].add(new P(from[i], i, time));
				q.add(new E(INFORM, from[i], time, null));
			}
			while(!q.isEmpty()){
				E event = q.poll();
//				System.out.println(event);
//				System.out.println(post[1]);
				int pos = event.data;
				if(event.type==BACK){
					if(post[pos].isEmpty()){
						exist[pos] = true; continue;
					}
					Collections.sort(post[pos]);
					if(event.t<post[pos].peek().t){
						exist[pos] = true; continue;
					}
					exist[pos] = false;
					T t = new T(pos);
					P p = post[pos].remove(0);
					t.list.add(p.id);
					int nx = next[pos][to[p.id]];
					for(int i=0;i<post[pos].size();i++){
						P tmp = post[pos].get(i);
						if(event.t<tmp.t)break;
						if(nx==next[pos][to[tmp.id]]){
							post[pos].remove(i);
							t.list.add(tmp.id);
							i--;
						}
					}
					int nt = event.t+e[pos][nx];
					q.add(new E(SEND, nx, nt, t));
					q.add(new E(INFORM, nx, nt, null));
				}
				else if(event.type==INFORM){
					if(!exist[pos])continue;
					if(post[pos].isEmpty())continue;
					Collections.sort(post[pos]);
					if(event.t<post[pos].peek().t)continue;
					exist[pos] = false;
					T t = new T(pos);
					P p = post[pos].remove(0);
					t.list.add(p.id);
					int nx = next[pos][to[p.id]];
					for(int i=0;i<post[pos].size();i++){
						P tmp = post[pos].get(i);
						if(event.t<tmp.t)break;
						if(nx==next[pos][to[tmp.id]]){
							post[pos].remove(i);
							t.list.add(tmp.id);
							i--;
						}
					}
					int nt = event.t+e[pos][nx];
					q.add(new E(SEND, nx, nt, t));
					q.add(new E(INFORM, nx, nt, null));
				}
				else if(event.type==SEND){
					T t = event.con;
					q.add(new E(BACK, t.from, event.t+e[pos][t.from], null));
					boolean offer = false;
					for(int id:t.list){
						if(pos==to[id]){
							res.add(new R(letter[id], event.t)); continue;
						}
						if(!offer)q.add(new E(INFORM, pos, event.t, null));
						offer = true;
						post[pos].add(new P(pos, id, event.t));
					}
				}
			}
			while(!res.isEmpty()){
				R r = res.poll();
				System.out.println(r.s+" "+r.t);
			}
		}
	}
	
	void debug(Object...o){
		System.out.println(Arrays.deepToString(o));
	}
	
	public static void main(String[] args) {
		new Main().run();
	}
}