Under construction

Still being built. Things may change

The Scariest Story (Basic)

Interview

Time limit1sMemory limit1024 MB

Summary
Given a story of n words and m global character positions, print the word number and the character's position within that word for each position.
Level

Easy3 of 10

Topics
Prefix sum, Binary search
Solved
No attempts yet

Problem

Little Jack wants to write the scariest story to frighten his friends on Halloween.

A story is a non-empty sequence of words separated by spaces. A word is a non-empty sequence of lowercase Latin letters.

The quality of a story depends not only on the words in it but also on the characters in those words.

Jack has already written a story of nn words. Now he wants to test mm hypotheses about it to confirm that it is really scary. For each hypothesis, he must find, given the position of a character in the story, the number of the word that contains it and the position of that character within the word.

Input

The first line contains two integers nn and mm separated by a space, the number of words in the story and the number of hypotheses (1≤n≤1051 \leq n \leq 10^5; 1≤m≤5×1051 \leq m \leq 5 \times 10^5).

The next line contains the story: nn words of lowercase Latin letters separated by spaces. The total length of all words does not exceed 10610^6.

The last line contains mm integers xix_i separated by spaces, the character positions in the hypotheses (1≤xi≤∑i=1n∣si∣1 \leq x_i \leq \sum_{i=1}^n |s_i|).

Output

Print mm pairs of numbers, one pair per line. The pair on line ii is the number of the word that contains the ii-th character and the number of that character within the word. Words and characters are numbered from 1.

Examples1

  1. Example 1

    Input
    3 15
    hell spirits fear
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    
    Expected output
    1 1
    1 2
    1 3
    1 4
    2 1
    2 2
    2 3
    2 4
    2 5
    2 6
    2 7
    3 1
    3 2
    3 3
    3 4