// http://codeforces.com/contest/667/problem/C
package main

import (
	"fmt"
	"bufio"
	"os"
	"sort"
)

// (c) Dmitriy Blokhin (sv.dblokhin@gmail.com)

func main () {
	var str string

	//f, _ := os.Open("input.txt")
	//input := bufio.NewReader(f)
	input := bufio.NewReader(os.Stdin)

	fmt.Fscanln(input, &str)

	n := len(str)
	ans := make(map[string]int)
	dp := make([]string, n + 1)
	dp[n] = "_"
	for i := n - 1; i >= 4; i-- {
		if len(dp[i + 1]) > 0 {

			if i - 2 >= 4 {
				sub := str[i - 2 + 1:i + 1]

				if len(dp[i + 1]) > 0 && sub != dp[i + 1] {
					ans[sub]++
					dp[i - 1] += sub
				}
			}

			if i - 3 >= 4 {
				sub := str[i - 3 + 1:i + 1]

				if len(dp[i + 1]) > 0 && sub != dp[i + 1] {
					ans[sub]++
					dp[i - 2] += sub
				}
			}
		}
	}

	// Answer
	fmt.Println(len(ans))
	strs := []string{}
	for i, _ := range ans {
		strs = append(strs, i)
	}

	sort.Strings(strs)
	for i := 0; i < len(strs); i++ {
		fmt.Println(strs[i])
	}
}

package main

import (
  "fmt"
  "sort"
)

func main() {
  var s string
  fmt.Scan(&s)

  dp := make([][]int, 10010)
  for i := range dp {
    dp[i] = make([]int, 5)
  }

  L := len(s)
  dp[L][2] = 1
  dp[L][3] = 1
  res := make(map[string]bool)
  for x:=L-2; x>=5; x-- {
    if x+2 == L {
      dp[x][2] = 1
    } else if x+3 == L {
      dp[x][3] = 1
    } else {
      if dp[x+2][2] == 1 && s[x:x+2] != s[x+2:x+4] {
          dp[x][2] = 1
      }
      if dp[x+2][3] == 1 {
        dp[x][2] = 1
      }

      if dp[x+3][2] == 1 {
        dp[x][3] = 1
      }
      if dp[x+3][3] == 1 && s[x:x+3] != s[x+3:x+6] {
        dp[x][3] = 1
      }
    }

    if dp[x][2]==1 {
      res[s[x:x+2]] = true
    }
    if dp[x][3]==1 {
      res[s[x:x+3]] = true
    }
  }
  //fmt.Println(len(res))
  //sort.Strings(res)
  sm := make([]string, len(res))
  j := 0
  for k, _ := range res {
    sm[j] = k
    j++
  }
  sort.Strings(sm)
  fmt.Println(len(sm))
  for _,v := range sm {
    fmt.Println(v)
  }
  //for _,v := range res {
  //  fmt.Println(v)
  //}
}

package main

import (
  "fmt"
  "sort"
)

type ResultSet []string

func suffix(s string) ResultSet {
  var dict = make(map[string]ResultSet)

  if len(s) < 2 {
    return ResultSet{}
  }
  if len(s) <= 3 {
    return ResultSet{s}
  }
  dict[s[:1]] = ResultSet{}
  dict[s[:2]] = ResultSet{s[:2]}
  dict[s[:3]] = ResultSet{s[:3]}

  for i:=3; i<len(s); i++ {
    a := s[i-1:i+1]
    //fmt.Println(a)
    //fmt.Println(s[i-3:i-1])

    var x []string = make([]string,0)
    if a != s[i-3:i-1] {
      if len(dict[s[:i-1]]) > 0 {
        x = append(dict[s[:i-1]], a)
      }
    } else {
      if len(dict[s[:i-1]]) == 1 {
        x = append(dict[s[:i-1]], a)
      }
    }

    b := s[i-2:i+1]
    var y []string = make([]string, 0)
    if (i < 5) || (b != s[i-5:i-2]) {
      if len(dict[s[:i-2]]) > 0 {
        y = append(dict[s[:i-2]], b)
      }
    } else {
      if len(dict[s[:i-2]]) == 0 {
        y = append(dict[s[:i-2]], b)
      }
    }

    dict[s[:i+1]] = append(x, y...)

  }
  //print_dict(dict)
  return dict[s]
}
func print_dict(d map[string]ResultSet) {
  for k,v := range d {
    fmt.Printf("%v->%v   ", k, v)
  }
}

func main() {
  //fmt.Println(suffix("yzzzz"))
  var s string
  fmt.Scan(&s)
  var res = make(map[string]int)
  for i:=5; i<len(s); i++ {
    for _,v := range suffix(s[i:]) {
      res[v] = 1
    }
  }
  fmt.Println(len(res))
  sm := make([]string, len(res))
  j := 0
  for k, _ := range res {
    sm[j] = k
    j++
  }
  sort.Strings(sm)
  for _,v := range sm {
    fmt.Println(v)
  }
  //fmt.Println(res)

}

package main

import (
  "fmt"
  "sort"
)

type ResultSet []string

func suffix(s string) ResultSet {
  var dict = make(map[string]ResultSet)

  if len(s) < 2 {
    return ResultSet{}
  }
  if len(s) <= 3 {
    return ResultSet{s}
  }
  dict[s[:1]] = ResultSet{}
  dict[s[:2]] = ResultSet{s[:2]}
  dict[s[:3]] = ResultSet{s[:3]}

  for i:=3; i<len(s); i++ {
    a := s[i-1:i+1]
    //fmt.Println(a)
    //fmt.Println(s[i-3:i-1])

    var x []string = make([]string,0)
    if a != s[i-3:i-1] {
      if len(dict[s[:i-1]]) > 0 {
        x = append(dict[s[:i-1]], a)
      }
    } /*else {
      x = dict[s[:i-1]]
    }*/

    b := s[i-2:i+1]
    var y []string = make([]string, 0)
    if (i < 5) || (b != s[i-5:i-2]) {
      if len(dict[s[:i-2]]) > 0 {
        y = append(dict[s[:i-2]], b)
      }
    } /*else {
      y = dict[s[:i-2]]
    }*/

    dict[s[:i+1]] = append(x, y...)

  }
  //print_dict(dict)
  return dict[s]
}
func print_dict(d map[string]ResultSet) {
  for k,v := range d {
    fmt.Printf("%v->%v   ", k, v)
  }
}

func main() {
  s := "abacabaca"
  var res = make(map[string]int)
  for i:=5; i<len(s); i++ {
    for _,v := range suffix(s[i:]) {
      res[v] = 1
    }
  }
  fmt.Println(len(res))
  sm := make([]string, len(res))
  j := 0
  for k, _ := range res {
    sm[j] = k
    j++
  }
  sort.Strings(sm)
  for _,v := range sm {
    fmt.Println(v)
  }
  //fmt.Println(res)

}

package main

import (
  "fmt"
  "sort"
)

func main() {
  var s string
  fmt.Scan(&s)

  dp := make([][]int, 100010)
  for i := range dp {
    dp[i] = make([]int, 5)
  }

  L := len(s)
  dp[L][2] = 1

  res := make([]string, 0)
  for x:=L-2; x>=5; x-- {
    if x+2 == L {
      dp[x][2] = 1
    } else if x+3 == L {
      dp[x][3] = 1
    } else {
      if dp[x+2][2] == 1 && s[x:x+2] != s[x+2:x+4] {
          dp[x][2] = 1
      }
      if dp[x+2][3] == 1 {
        dp[x][2] = 1
      }

      if dp[x+3][2] == 1 {
        dp[x][3] = 1
      }
      if dp[x+3][3] == 1 && s[x:x+3] != s[x+3:x+6] {
        dp[x][3] = 1
      }
    }

    if dp[x][2]==1 {
      res = append(res, s[x:x+2])
    }
    if dp[x][3]==1 {
      res = append(res, s[x:x+3])
    }
  }
  fmt.Println(len(res))
  sort.Strings(res)
  for _,v := range res {
    fmt.Println(v)
  }
}

package main

import (
  "fmt"
  "sort"
)

type ResultSet []string

func suffix(s string) ResultSet {
  var dict = make(map[string]ResultSet)

  if len(s) < 2 {
    return ResultSet{}
  }
  if len(s) <= 3 {
    return ResultSet{s}
  }
  dict[s[:1]] = ResultSet{}
  dict[s[:2]] = ResultSet{s[:2]}
  dict[s[:3]] = ResultSet{s[:3]}

  for i:=3; i<len(s); i++ {
    a := s[i-1:i+1]
    //fmt.Println(a)
    //fmt.Println(s[i-3:i-1])

    var x []string = make([]string,0)
    if a != s[i-3:i-1] {
      if len(dict[s[:i-1]]) > 0 {
        x = append(dict[s[:i-1]], a)
      }
    } else {
      if len(dict[s[:i-1]]) == 1 {
        x = append(dict[s[:i-1]], a)
      }
    }

    b := s[i-2:i+1]
    var y []string = make([]string, 0)
    if (i < 5) || (b != s[i-5:i-2]) {
      if len(dict[s[:i-2]]) > 0 {
        y = append(dict[s[:i-2]], b)
      }
    } else {
      if len(dict[s[:i-2]]) == 1 {
        y = append(dict[s[:i-2]], b)
      }
    }

    dict[s[:i+1]] = append(x, y...)

  }
  //print_dict(dict)
  return dict[s]
}
func print_dict(d map[string]ResultSet) {
  for k,v := range d {
    fmt.Printf("%v->%v   ", k, v)
  }
}

func main() {
  //fmt.Println(suffix("yzzzz"))
  var s string
  fmt.Scan(&s)
  var res = make(map[string]int)
  for i:=5; i<len(s); i++ {
    for _,v := range suffix(s[i:]) {
      res[v] = 1
    }
  }
  fmt.Println(len(res))
  sm := make([]string, len(res))
  j := 0
  for k, _ := range res {
    sm[j] = k
    j++
  }
  sort.Strings(sm)
  for _,v := range sm {
    fmt.Println(v)
  }
  //fmt.Println(res)

}

package main

import (
  "fmt"
  "sort"
)

type ResultSet []string

func suffix(s string) ResultSet {
  var dict = make(map[string]ResultSet)

  if len(s) < 2 {
    return ResultSet{}
  }
  if len(s) <= 3 {
    return ResultSet{s}
  }
  dict[s[:1]] = ResultSet{}
  dict[s[:2]] = ResultSet{s[:2]}
  dict[s[:3]] = ResultSet{s[:3]}

  for i:=3; i<len(s); i++ {
    a := s[i-1:i+1]
    //fmt.Println(a)
    //fmt.Println(s[i-3:i-1])

    var x []string = make([]string,0)
    if a != s[i-3:i-1] {
      if len(dict[s[:i-1]]) > 0 {
        x = append(dict[s[:i-1]], a)
      }
    } /*else {
      x = dict[s[:i-1]]
    }*/

    b := s[i-2:i+1]
    var y []string = make([]string, 0)
    if (i < 5) || (b != s[i-5:i-2]) {
      if len(dict[s[:i-2]]) > 0 {
        y = append(dict[s[:i-2]], b)
      }
    } /*else {
      y = dict[s[:i-2]]
    }*/

    dict[s[:i+1]] = append(x, y...)

  }
  //print_dict(dict)
  return dict[s]
}
func print_dict(d map[string]ResultSet) {
  for k,v := range d {
    fmt.Printf("%v->%v   ", k, v)
  }
}

func main() {
  var s string
  fmt.Scan(&s)
  var res = make(map[string]int)
  for i:=5; i<len(s); i++ {
    for _,v := range suffix(s[i:]) {
      res[v] = 1
    }
  }
  fmt.Println(len(res))
  sm := make([]string, len(res))
  j := 0
  for k, _ := range res {
    sm[j] = k
    j++
  }
  sort.Strings(sm)
  for _,v := range sm {
    fmt.Println(v)
  }
  //fmt.Println(res)

}

// http://codeforces.com/contest/667/problem/C
package main

import (
	"fmt"
	"bufio"
	"os"
	"sort"
)

// (c) Dmitriy Blokhin (sv.dblokhin@gmail.com)

func main () {
	var str string

	//f, _ := os.Open("input.txt")
	//input := bufio.NewReader(f)
	input := bufio.NewReader(os.Stdin)

	fmt.Fscanln(input, &str)

	n := len(str)
	ans := make(map[string]int)
	dp := make([]bool, n + 1)
	dp[n] = true
	for i := n - 1; i >= 4; i-- {
		if dp[i + 1] {

			if i - 2 >= 4 {
				sub := str[i - 2 + 1:i + 1]

				// check doublicate
				dublicate := false
				if i - 2 + 5 <= n {
					dublicate = sub == str[i - 2 + 3:i - 2 + 5]
				}

				if !dublicate {
					ans[sub]++
					dp[i - 1] = true
				}
			}

			if i - 3 >= 4 {
				sub := str[i - 3 + 1:i + 1]

				// check doublicate
				dublicate := false
				if i + 4 <= n {
					dublicate = sub == str[i - 3 + 4:i + 4]
				}

				if !dublicate {
					ans[sub]++
					dp[i - 2] = true
				}
			}
		}
	}

	// Answer
	fmt.Println(len(ans))
	strs := []string{}
	for i, _ := range ans {
		strs = append(strs, i)
	}

	sort.Strings(strs)
	for i := 0; i < len(strs); i++ {
		fmt.Println(strs[i])
	}
}

// http://codeforces.com/contest/667/problem/C
package main

import (
	"fmt"
	"bufio"
	"os"
	"sort"
)

// (c) Dmitriy Blokhin (sv.dblokhin@gmail.com)

func main () {
	var str string

	//f, _ := os.Open("input.txt")
	//input := bufio.NewReader(f)
	input := bufio.NewReader(os.Stdin)

	fmt.Fscanln(input, &str)

	n := len(str)
	ans := make(map[string]int)
	dp := make([]bool, n)
	dp[n - 1] = true
	for i := n - 1; i >= 4; i-- {
		if dp[i] {

			if i - 2 >= 4 {
				sub := str[i - 2 + 1:i + 1]

				// check doublicate
				dublicate := false
				if i - 4 >= 4 {
					dublicate = sub == str[i - 4 + 1:i - 4 + 1]
				}

				if !dublicate {
					ans[sub]++
					dp[i - 2] = true
				}

			}

			if i - 3 >= 4 {
				sub := str[i - 3 + 1:i + 1]

				// check doublicate
				dublicate := false
				if i - 6 >= 4 {
					dublicate = sub == str[i - 6 + 1:i - 6 + 4]
				}

				if !dublicate {
					ans[sub]++
					dp[i - 3] = true
				}
			}
		}

	}

	// Answer
	fmt.Println(len(ans))
	strs := []string{}
	for i, _ := range ans {
		strs = append(strs, i)
	}

	sort.Strings(strs)
	for i := 0; i < len(strs); i++ {
		fmt.Println(strs[i])
	}
}

// http://codeforces.com/contest/667/problem/C
package main

import (
	"fmt"
	"bufio"
	"os"
	"sort"
)

// (c) Dmitriy Blokhin (sv.dblokhin@gmail.com)

func main () {
	var str string

	//f, _ := os.Open("input.txt")
	//input := bufio.NewReader(f)
	input := bufio.NewReader(os.Stdin)

	fmt.Fscanln(input, &str)

	n := len(str)
	ans := make(map[string]int)
	dp := make([]bool, n + 1)
	dp[n] = true
	for i := n - 1; i >= 4; i-- {
		if dp[i + 1] {

			if i - 2 >= 4 {
				sub := str[i - 2 + 1:i + 1]

				// check doublicate
				dublicate := false
				if i - 2 + 5 <= n {
					dublicate = sub == str[i - 2 + 3:i - 2 + 5]
				}

				if !dublicate {
					ans[sub]++
					dp[i - 1] = true
				}
			}

			if i - 3 >= 4 {
				sub := str[i - 3 + 1:i + 1]

				// check doublicate
				dublicate := false
				if i + 4 <= n {
					dublicate = sub == str[i - 3 + 4:i + 4]
				}

				if !dublicate {
					ans[sub]++
					dp[i - 2] = true
				}
			}
		}
	}

	// Answer
	fmt.Println(len(ans))
	strs := []string{}
	for i, _ := range ans {
		strs = append(strs, i)
	}

	//sort.Strings(strs)
	for i := 0; i < len(strs); i++ {
		fmt.Println(strs[i])
	}
	sort.Strings(strs)
}


package main

import (
	"bufio"
	"fmt"
	"os"
)

type task struct {
	letters     [40]int
	letterIndex int

	m int
	b [60]int

	ans [60]int
}

func (t *task) Input(reader *bufio.Reader) {
	var s string
	fmt.Fscanf(reader, "%s\n", &s)
	for i := 0; i < len(s); i++ {
		index := int(s[i] - 'a')
		t.letters[index]++

		if t.letterIndex < index {
			t.letterIndex = index
		}
	}

	fmt.Fscanf(reader, "%d\n", &t.m)
	for i := 0; i < t.m; i++ {
		if i+1 == t.m {
			fmt.Fscanf(reader, "%d\n", &t.b[i])
		} else {
			fmt.Fscanf(reader, "%d ", &t.b[i])
		}
	}
}

func (t *task) Calc() {
	for {
		zeroIndex := make([]int, 0, 60)
		for i := 0; i < t.m; i++ {
			if t.b[i] == 0 {
				zeroIndex = append(zeroIndex, i)
			}
		}

		if len(zeroIndex) == 0 {
			return
		}

		for ; t.letterIndex >= 0; t.letterIndex-- {
			if t.letters[t.letterIndex] >= len(zeroIndex) {
				break
			}
		}

		for _, i := range zeroIndex {
			t.ans[i] = t.letterIndex
			t.b[i] = -1
		}

		t.letterIndex--

		for i := 0; i < t.m; i++ {
			if t.b[i] > 0 {
				for _, zi := range zeroIndex {
					if zi > i {
						t.b[i] -= (zi - i)
					} else {
						t.b[i] -= (i - zi)
					}
				}
			}
		}
	}
}

func (t *task) PrintAns() {
	for i := 0; i < t.m; i++ {
		fmt.Printf("%c", t.ans[i]+'a')
	}

	fmt.Println()
}

func main() {
	reader := bufio.NewReader(os.Stdin)

	var t int

	fmt.Fscanf(reader, "%d\n", &t)
	for ; t > 0; t-- {
		var tk task
		tk.Input(reader)
		tk.Calc()
		tk.PrintAns()
	}
}

/*
URL:
https://codeforces.com/problemset/problem/1367/D
*/

package main

import (
	"bufio"
	"errors"
	"fmt"
	"io"
	"math"
	"os"
	"strconv"
)

/********** FAU standard libraries **********/

//fmt.Sprintf("%b\n", 255) 	// binary expression

/********** I/O usage **********/

//str := ReadString()
//i := ReadInt()
//X := ReadIntSlice(n)
//S := ReadRuneSlice()
//a := ReadFloat64()
//A := ReadFloat64Slice(n)

//str := ZeroPaddingRuneSlice(num, 32)
//str := PrintIntsLine(X...)

/*******************************************************************/

const (
	// General purpose
	MOD          = 1000000000 + 7
	ALPHABET_NUM = 26
	INF_INT64    = math.MaxInt64
	INF_BIT60    = 1 << 60
	INF_INT32    = math.MaxInt32
	INF_BIT30    = 1 << 30
	NIL          = -1

	// for dijkstra, prim, and so on
	WHITE = 0
	GRAY  = 1
	BLACK = 2
)

func init() {
	// bufio.ScanWords <---> bufio.ScanLines
	ReadString = newReadString(os.Stdin, bufio.ScanWords)
	stdout = bufio.NewWriter(os.Stdout)
}

var (
	q int

	S []rune
	m int
	B []int

	memo []int
	nums [50]int
)

func main() {
	q = ReadInt()
	for i := 0; i < q; i++ {
		S = ReadRuneSlice()
		m = ReadInt()
		B = ReadIntSlice(m)

		solve()
	}
}

func solve() {
	nums = [50]int{}
	for _, r := range S {
		nums[r-'a']++
	}

	memo = make([]int, m)
	answers := make([]rune, m)

	for !isComplete(memo) {
		var c rune

		target := findZero(B, memo)
		for r := 'z'; r >= 'a'; r-- {
			if nums[r-'a'] >= len(target) {
				nums[r-'a'] = 0
				c = r
				break
			}
			nums[r-'a'] = 0
		}

		fix(B, memo, answers, c)
		decrease(B, target)
	}

	fmt.Println(string(answers))
}

func decrease(B, target []int) {
	for _, t := range target {
		for i := 0; i < m; i++ {
			if B[i] > 0 {
				d := AbsInt(i - t)
				B[i] -= d
			}
		}
	}
}

// AbsInt is integer version of math.Abs
func AbsInt(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

func fix(B, memo []int, answers []rune, c rune) {
	for i := 0; i < len(B); i++ {
		if B[i] == 0 && memo[i] == 0 {
			memo[i] = 1
			answers[i] = c
		}
	}
}

func findZero(B, memo []int) []int {
	res := []int{}

	for i, b := range B {
		if b == 0 && memo[i] != 1 {
			res = append(res, i)
		}
	}

	return res
}

func isComplete(memo []int) bool {
	for _, a := range memo {
		if a == 0 {
			return false
		}
	}
	return true
}

/*******************************************************************/

/*********** I/O ***********/

var (
	// ReadString returns a WORD string.
	ReadString func() string
	stdout     *bufio.Writer
)

func newReadString(ior io.Reader, sf bufio.SplitFunc) func() string {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+9)) // for Codeforces
	r.Split(sf)

	return func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
}

// ReadInt returns an integer.
func ReadInt() int {
	return int(readInt64())
}
func ReadInt2() (int, int) {
	return int(readInt64()), int(readInt64())
}
func ReadInt3() (int, int, int) {
	return int(readInt64()), int(readInt64()), int(readInt64())
}
func ReadInt4() (int, int, int, int) {
	return int(readInt64()), int(readInt64()), int(readInt64()), int(readInt64())
}

// ReadInt64 returns as integer as int64.
func ReadInt64() int64 {
	return readInt64()
}
func ReadInt64_2() (int64, int64) {
	return readInt64(), readInt64()
}
func ReadInt64_3() (int64, int64, int64) {
	return readInt64(), readInt64(), readInt64()
}
func ReadInt64_4() (int64, int64, int64, int64) {
	return readInt64(), readInt64(), readInt64(), readInt64()
}

func readInt64() int64 {
	i, err := strconv.ParseInt(ReadString(), 0, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

// ReadIntSlice returns an integer slice that has n integers.
func ReadIntSlice(n int) []int {
	b := make([]int, n)
	for i := 0; i < n; i++ {
		b[i] = ReadInt()
	}
	return b
}

// ReadInt64Slice returns as int64 slice that has n integers.
func ReadInt64Slice(n int) []int64 {
	b := make([]int64, n)
	for i := 0; i < n; i++ {
		b[i] = ReadInt64()
	}
	return b
}

// ReadFloat64 returns an float64.
func ReadFloat64() float64 {
	return float64(readFloat64())
}

func readFloat64() float64 {
	f, err := strconv.ParseFloat(ReadString(), 64)
	if err != nil {
		panic(err.Error())
	}
	return f
}

// ReadFloatSlice returns an float64 slice that has n float64.
func ReadFloat64Slice(n int) []float64 {
	b := make([]float64, n)
	for i := 0; i < n; i++ {
		b[i] = ReadFloat64()
	}
	return b
}

// ReadRuneSlice returns a rune slice.
func ReadRuneSlice() []rune {
	return []rune(ReadString())
}

/*********** Debugging ***********/

// ZeroPaddingRuneSlice returns binary expressions of integer n with zero padding.
// For debugging use.
func ZeroPaddingRuneSlice(n, digitsNum int) []rune {
	sn := fmt.Sprintf("%b", n)

	residualLength := digitsNum - len(sn)
	if residualLength <= 0 {
		return []rune(sn)
	}

	zeros := make([]rune, residualLength)
	for i := 0; i < len(zeros); i++ {
		zeros[i] = '0'
	}

	res := []rune{}
	res = append(res, zeros...)
	res = append(res, []rune(sn)...)

	return res
}

// Strtoi is a wrapper of strconv.Atoi().
// If strconv.Atoi() returns an error, Strtoi calls panic.
func Strtoi(s string) int {
	if i, err := strconv.Atoi(s); err != nil {
		panic(errors.New("[argument error]: Strtoi only accepts integer string"))
	} else {
		return i
	}
}

// PrintIntsLine returns integers string delimited by a space.
func PrintIntsLine(A ...int) string {
	res := []rune{}

	for i := 0; i < len(A); i++ {
		str := strconv.Itoa(A[i])
		res = append(res, []rune(str)...)

		if i != len(A)-1 {
			res = append(res, ' ')
		}
	}

	return string(res)
}

// PrintIntsLine returns integers string delimited by a space.
func PrintInts64Line(A ...int64) string {
	res := []rune{}

	for i := 0; i < len(A); i++ {
		str := strconv.FormatInt(A[i], 10) // 64bit int version
		res = append(res, []rune(str)...)

		if i != len(A)-1 {
			res = append(res, ' ')
		}
	}

	return string(res)
}

// PrintfDebug is wrapper of fmt.Fprintf(os.Stderr, format, a...)
func PrintfDebug(format string, a ...interface{}) {
	fmt.Fprintf(os.Stderr, format, a...)
}

// PrintfBufStdout is function for output strings to buffered os.Stdout.
// You may have to call stdout.Flush() finally.
func PrintfBufStdout(format string, a ...interface{}) {
	fmt.Fprintf(stdout, format, a...)
}

package main

import (
	"bufio"
	. "fmt"
	"io"
	"os"
)

// github.com/EndlessCheng/codeforces-go
func CF1367D(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	abs := func(x int) int {
		if x < 0 {
			return -x
		}
		return x
	}

	var t, n int
	var s []byte
	for Fscan(in, &t); t > 0; t-- {
		Fscan(in, &s, &n)
		cnt := [26]int{}
		for _, b := range s {
			cnt[b-'a']++
		}
		p := byte(25)
		q := []int{}
		a := make([]int, n)
		for i := range a {
			Fscan(in, &a[i])
			if a[i] == 0 {
				q = append(q, i)
			}
		}

		ans := make([]byte, n)
		for ; len(q) > 0; p-- {
			for ; cnt[p] < len(q); p-- {
			}
			qq := q
			q = []int{}
			for _, i := range qq {
				ans[i] = 'a' + p
				for j := range a {
					if j != i {
						if a[j] -= abs(j - i); a[j] == 0 {
							q = append(q, j)
						}
					}
				}
			}
		}
		Fprintln(out, string(ans))
	}
}

func main() { CF1367D(os.Stdin, os.Stdout) }

package main

import (
	"bufio"
	"fmt"
	"os"
)

var nTest, n int
var a [55]int
var s string

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)

	fmt.Fscan(in, &nTest)
	for t := 0; t < nTest; t++ {
		fmt.Fscan(in, &s, &n)
		var res [55]int
		cnt := map[int]int{}
		for i := 0; i < len(s); i++ {
			cnt[int(s[i])]++
		}

		for i := 0; i < n; i++ {
			fmt.Fscan(in, &a[i])
		}

		fill := 0
		char := int('z')
		for fill != n {
			zero := []int{}
			for i := 0; i < n; i++ {
				if a[i] == 0 && res[i] == 0 {
					zero = append(zero, i)
				}
			}
			for cnt[char] < len(zero) {
				char--
			}
			cnt[char] -= len(zero)
			fill += len(zero)
			for j := 0; j < len(zero); j++ {
				res[zero[j]] = char
				for k := 0; k < n; k++ {
					if a[k] != 0 {
						if zero[j] > k {
							a[k] -= zero[j] - k
						} else {
							a[k] -= k - zero[j]
						}
					}
				}
			}
			char--
		}

		for i := 0; i < n; i++ {
			fmt.Fprintf(out, "%c", res[i])
		}
		fmt.Fprintln(out)
	}

	out.Flush()
}

package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
)

func main() {
	reader := bufio.NewReader(os.Stdin)

	tc := readNum(reader)

	for tc > 0 {
		tc--
		s, _ := reader.ReadString('\n')
		s = s[:len(s)-1]
		m := readNum(reader)
		B := readNNums(reader, m)

		fmt.Println(solve(s, m, B))
	}
}

func readInt(bytes []byte, from int, val *int) int {
	i := from
	sign := 1
	if bytes[i] == '-' {
		sign = -1
		i++
	}
	tmp := 0
	for i < len(bytes) && bytes[i] >= '0' && bytes[i] <= '9' {
		tmp = tmp*10 + int(bytes[i]-'0')
		i++
	}
	*val = tmp * sign
	return i
}

func readNum(reader *bufio.Reader) (a int) {
	bs, _ := reader.ReadBytes('\n')
	readInt(bs, 0, &a)
	return
}

func readTwoNums(reader *bufio.Reader) (a int, b int) {
	res := readNNums(reader, 2)
	a, b = res[0], res[1]
	return
}

func readThreeNums(reader *bufio.Reader) (a int, b int, c int) {
	res := readNNums(reader, 3)
	a, b, c = res[0], res[1], res[2]
	return
}

func readNNums(reader *bufio.Reader, n int) []int {
	res := make([]int, n)
	x := 0
	bs, _ := reader.ReadBytes('\n')
	for i := 0; i < n; i++ {
		for x < len(bs) && (bs[x] < '0' || bs[x] > '9') && bs[x] != '-' {
			x++
		}
		x = readInt(bs, x, &res[i])
	}
	return res
}

func readUint64(bytes []byte, from int, val *uint64) int {
	i := from

	var tmp uint64
	for i < len(bytes) && bytes[i] >= '0' && bytes[i] <= '9' {
		tmp = tmp*10 + uint64(bytes[i]-'0')
		i++
	}
	*val = tmp

	return i
}

func solve(s string, m int, B []int) string {
	mem := make(map[byte]int)

	for i := 0; i < len(s); i++ {
		mem[s[i]]++
	}

	xx := make([]byte, 0, len(mem))

	for x := range mem {
		xx = append(xx, x)
	}

	sort.Sort(Bytes(xx))

	res := make([]byte, m)

	for i := 0; i < m; i++ {
		res[i] = ' '
	}
	zs := make([]int, m)

	for i := 0; i < len(xx); i++ {
		x := xx[i]

		// find 0
		var p int
		var sum int
		for j := 0; j < m; j++ {
			if B[j] == 0 && res[j] == ' ' {
				zs[p] = j
				p++
				sum += j
			}
		}

		if mem[x] < p {
			continue
		}

		for j := 0; j < p; j++ {
			res[zs[j]] = x
		}

		var sum2 int
		var k int
		// need to update B
		for j := 0; j < m; j++ {
			if B[j] == 0 {
				continue
			}
			for k < p && zs[k] < j {
				sum2 += zs[k]
				k++
			}
			B[j] -= (k*j - sum2)
			B[j] -= (sum - sum2 - (p-k)*j)
		}
	}

	return string(res)
}

type Bytes []byte

func (bs Bytes) Len() int {
	return len(bs)
}

func (bs Bytes) Less(i, j int) bool {
	return bs[i] > bs[j]
}

func (bs Bytes) Swap(i, j int) {
	bs[i], bs[j] = bs[j], bs[i]
}

/*
URL:
https://codeforces.com/problemset/problem/1367/D
*/

package main

import (
	"bufio"
	"errors"
	"fmt"
	"io"
	"math"
	"os"
	"strconv"
)

/********** FAU standard libraries **********/

//fmt.Sprintf("%b\n", 255) 	// binary expression

/********** I/O usage **********/

//str := ReadString()
//i := ReadInt()
//X := ReadIntSlice(n)
//S := ReadRuneSlice()
//a := ReadFloat64()
//A := ReadFloat64Slice(n)

//str := ZeroPaddingRuneSlice(num, 32)
//str := PrintIntsLine(X...)

/*******************************************************************/

const (
	// General purpose
	MOD          = 1000000000 + 7
	ALPHABET_NUM = 26
	INF_INT64    = math.MaxInt64
	INF_BIT60    = 1 << 60
	INF_INT32    = math.MaxInt32
	INF_BIT30    = 1 << 30
	NIL          = -1

	// for dijkstra, prim, and so on
	WHITE = 0
	GRAY  = 1
	BLACK = 2
)

func init() {
	// bufio.ScanWords <---> bufio.ScanLines
	ReadString = newReadString(os.Stdin, bufio.ScanWords)
	stdout = bufio.NewWriter(os.Stdout)
}

var (
	q int

	S []rune
	m int
	B []int

	memo []int
	nums [50]int
)

func main() {
	q = ReadInt()
	for i := 0; i < q; i++ {
		S = ReadRuneSlice()
		m = ReadInt()
		B = ReadIntSlice(m)

		solve()
	}
}

func solve() {
	nums = [50]int{}
	for _, r := range S {
		nums[r-'a']++
	}

	memo = make([]int, m)
	answers := make([]rune, m)

	for !isComplete(memo) {
		var c rune

		target := findZero(B, memo)
		for r := 'z'; r >= 'a'; r-- {
			if nums[r-'a'] >= len(target) {
				nums[r-'a'] -= len(target)
				c = r
				break
			}
		}

		fix(B, memo, answers, c)
		decrease(B, target)
	}

	fmt.Println(string(answers))
}

func decrease(B, target []int) {
	for _, t := range target {
		for i := 0; i < m; i++ {
			d := AbsInt(i - t)
			B[i] -= d
		}
	}
}

// AbsInt is integer version of math.Abs
func AbsInt(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

func fix(B, memo []int, answers []rune, c rune) {
	for i := 0; i < len(B); i++ {
		if B[i] == 0 && memo[i] == 0 {
			memo[i] = 1
			answers[i] = c
		}
	}
}

func findZero(B, memo []int) []int {
	res := []int{}

	for i, b := range B {
		if b == 0 && memo[i] != 1 {
			res = append(res, i)
		}
	}

	return res
}

func isComplete(memo []int) bool {
	for _, a := range memo {
		if a == 0 {
			return false
		}
	}
	return true
}

/*******************************************************************/

/*********** I/O ***********/

var (
	// ReadString returns a WORD string.
	ReadString func() string
	stdout     *bufio.Writer
)

func newReadString(ior io.Reader, sf bufio.SplitFunc) func() string {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+9)) // for Codeforces
	r.Split(sf)

	return func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
}

// ReadInt returns an integer.
func ReadInt() int {
	return int(readInt64())
}
func ReadInt2() (int, int) {
	return int(readInt64()), int(readInt64())
}
func ReadInt3() (int, int, int) {
	return int(readInt64()), int(readInt64()), int(readInt64())
}
func ReadInt4() (int, int, int, int) {
	return int(readInt64()), int(readInt64()), int(readInt64()), int(readInt64())
}

// ReadInt64 returns as integer as int64.
func ReadInt64() int64 {
	return readInt64()
}
func ReadInt64_2() (int64, int64) {
	return readInt64(), readInt64()
}
func ReadInt64_3() (int64, int64, int64) {
	return readInt64(), readInt64(), readInt64()
}
func ReadInt64_4() (int64, int64, int64, int64) {
	return readInt64(), readInt64(), readInt64(), readInt64()
}

func readInt64() int64 {
	i, err := strconv.ParseInt(ReadString(), 0, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

// ReadIntSlice returns an integer slice that has n integers.
func ReadIntSlice(n int) []int {
	b := make([]int, n)
	for i := 0; i < n; i++ {
		b[i] = ReadInt()
	}
	return b
}

// ReadInt64Slice returns as int64 slice that has n integers.
func ReadInt64Slice(n int) []int64 {
	b := make([]int64, n)
	for i := 0; i < n; i++ {
		b[i] = ReadInt64()
	}
	return b
}

// ReadFloat64 returns an float64.
func ReadFloat64() float64 {
	return float64(readFloat64())
}

func readFloat64() float64 {
	f, err := strconv.ParseFloat(ReadString(), 64)
	if err != nil {
		panic(err.Error())
	}
	return f
}

// ReadFloatSlice returns an float64 slice that has n float64.
func ReadFloat64Slice(n int) []float64 {
	b := make([]float64, n)
	for i := 0; i < n; i++ {
		b[i] = ReadFloat64()
	}
	return b
}

// ReadRuneSlice returns a rune slice.
func ReadRuneSlice() []rune {
	return []rune(ReadString())
}

/*********** Debugging ***********/

// ZeroPaddingRuneSlice returns binary expressions of integer n with zero padding.
// For debugging use.
func ZeroPaddingRuneSlice(n, digitsNum int) []rune {
	sn := fmt.Sprintf("%b", n)

	residualLength := digitsNum - len(sn)
	if residualLength <= 0 {
		return []rune(sn)
	}

	zeros := make([]rune, residualLength)
	for i := 0; i < len(zeros); i++ {
		zeros[i] = '0'
	}

	res := []rune{}
	res = append(res, zeros...)
	res = append(res, []rune(sn)...)

	return res
}

// Strtoi is a wrapper of strconv.Atoi().
// If strconv.Atoi() returns an error, Strtoi calls panic.
func Strtoi(s string) int {
	if i, err := strconv.Atoi(s); err != nil {
		panic(errors.New("[argument error]: Strtoi only accepts integer string"))
	} else {
		return i
	}
}

// PrintIntsLine returns integers string delimited by a space.
func PrintIntsLine(A ...int) string {
	res := []rune{}

	for i := 0; i < len(A); i++ {
		str := strconv.Itoa(A[i])
		res = append(res, []rune(str)...)

		if i != len(A)-1 {
			res = append(res, ' ')
		}
	}

	return string(res)
}

// PrintIntsLine returns integers string delimited by a space.
func PrintInts64Line(A ...int64) string {
	res := []rune{}

	for i := 0; i < len(A); i++ {
		str := strconv.FormatInt(A[i], 10) // 64bit int version
		res = append(res, []rune(str)...)

		if i != len(A)-1 {
			res = append(res, ' ')
		}
	}

	return string(res)
}

// PrintfDebug is wrapper of fmt.Fprintf(os.Stderr, format, a...)
func PrintfDebug(format string, a ...interface{}) {
	fmt.Fprintf(os.Stderr, format, a...)
}

// PrintfBufStdout is function for output strings to buffered os.Stdout.
// You may have to call stdout.Flush() finally.
func PrintfBufStdout(format string, a ...interface{}) {
	fmt.Fprintf(stdout, format, a...)
}

/*
URL:
https://codeforces.com/problemset/problem/1367/D
*/

package main

import (
	"bufio"
	"errors"
	"fmt"
	"io"
	"math"
	"os"
	"strconv"
)

/********** FAU standard libraries **********/

//fmt.Sprintf("%b\n", 255) 	// binary expression

/********** I/O usage **********/

//str := ReadString()
//i := ReadInt()
//X := ReadIntSlice(n)
//S := ReadRuneSlice()
//a := ReadFloat64()
//A := ReadFloat64Slice(n)

//str := ZeroPaddingRuneSlice(num, 32)
//str := PrintIntsLine(X...)

/*******************************************************************/

const (
	// General purpose
	MOD          = 1000000000 + 7
	ALPHABET_NUM = 26
	INF_INT64    = math.MaxInt64
	INF_BIT60    = 1 << 60
	INF_INT32    = math.MaxInt32
	INF_BIT30    = 1 << 30
	NIL          = -1

	// for dijkstra, prim, and so on
	WHITE = 0
	GRAY  = 1
	BLACK = 2
)

func init() {
	// bufio.ScanWords <---> bufio.ScanLines
	ReadString = newReadString(os.Stdin, bufio.ScanWords)
	stdout = bufio.NewWriter(os.Stdout)
}

var (
	q int

	S []rune
	m int
	B []int

	memo []int
	nums [50]int
)

func main() {
	q = ReadInt()
	for i := 0; i < q; i++ {
		S = ReadRuneSlice()
		m = ReadInt()
		B = ReadIntSlice(m)

		solve()
	}
}

func solve() {
	nums = [50]int{}
	for _, r := range S {
		nums[r-'a']++
	}

	memo = make([]int, m)
	answers := make([]rune, m)

	for !isComplete(memo) {
		var c rune

		target := findZero(B, memo)
		for r := 'z'; r >= 'a'; r-- {
			if nums[r-'a'] >= len(target) {
				nums[r-'a'] -= len(target)
				c = r
				break
			}
		}

		fix(B, memo, answers, c)
		decrease(B, target)
	}

	fmt.Println(string(answers))
}

func decrease(B, target []int) {
	for _, t := range target {
		for i := 0; i < m; i++ {
			if B[i] > 0 {
				d := AbsInt(i - t)
				B[i] -= d
			}
		}
	}
}

// AbsInt is integer version of math.Abs
func AbsInt(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

func fix(B, memo []int, answers []rune, c rune) {
	for i := 0; i < len(B); i++ {
		if B[i] == 0 && memo[i] == 0 {
			memo[i] = 1
			answers[i] = c
		}
	}
}

func findZero(B, memo []int) []int {
	res := []int{}

	for i, b := range B {
		if b == 0 && memo[i] != 1 {
			res = append(res, i)
		}
	}

	return res
}

func isComplete(memo []int) bool {
	for _, a := range memo {
		if a == 0 {
			return false
		}
	}
	return true
}

/*******************************************************************/

/*********** I/O ***********/

var (
	// ReadString returns a WORD string.
	ReadString func() string
	stdout     *bufio.Writer
)

func newReadString(ior io.Reader, sf bufio.SplitFunc) func() string {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+9)) // for Codeforces
	r.Split(sf)

	return func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
}

// ReadInt returns an integer.
func ReadInt() int {
	return int(readInt64())
}
func ReadInt2() (int, int) {
	return int(readInt64()), int(readInt64())
}
func ReadInt3() (int, int, int) {
	return int(readInt64()), int(readInt64()), int(readInt64())
}
func ReadInt4() (int, int, int, int) {
	return int(readInt64()), int(readInt64()), int(readInt64()), int(readInt64())
}

// ReadInt64 returns as integer as int64.
func ReadInt64() int64 {
	return readInt64()
}
func ReadInt64_2() (int64, int64) {
	return readInt64(), readInt64()
}
func ReadInt64_3() (int64, int64, int64) {
	return readInt64(), readInt64(), readInt64()
}
func ReadInt64_4() (int64, int64, int64, int64) {
	return readInt64(), readInt64(), readInt64(), readInt64()
}

func readInt64() int64 {
	i, err := strconv.ParseInt(ReadString(), 0, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

// ReadIntSlice returns an integer slice that has n integers.
func ReadIntSlice(n int) []int {
	b := make([]int, n)
	for i := 0; i < n; i++ {
		b[i] = ReadInt()
	}
	return b
}

// ReadInt64Slice returns as int64 slice that has n integers.
func ReadInt64Slice(n int) []int64 {
	b := make([]int64, n)
	for i := 0; i < n; i++ {
		b[i] = ReadInt64()
	}
	return b
}

// ReadFloat64 returns an float64.
func ReadFloat64() float64 {
	return float64(readFloat64())
}

func readFloat64() float64 {
	f, err := strconv.ParseFloat(ReadString(), 64)
	if err != nil {
		panic(err.Error())
	}
	return f
}

// ReadFloatSlice returns an float64 slice that has n float64.
func ReadFloat64Slice(n int) []float64 {
	b := make([]float64, n)
	for i := 0; i < n; i++ {
		b[i] = ReadFloat64()
	}
	return b
}

// ReadRuneSlice returns a rune slice.
func ReadRuneSlice() []rune {
	return []rune(ReadString())
}

/*********** Debugging ***********/

// ZeroPaddingRuneSlice returns binary expressions of integer n with zero padding.
// For debugging use.
func ZeroPaddingRuneSlice(n, digitsNum int) []rune {
	sn := fmt.Sprintf("%b", n)

	residualLength := digitsNum - len(sn)
	if residualLength <= 0 {
		return []rune(sn)
	}

	zeros := make([]rune, residualLength)
	for i := 0; i < len(zeros); i++ {
		zeros[i] = '0'
	}

	res := []rune{}
	res = append(res, zeros...)
	res = append(res, []rune(sn)...)

	return res
}

// Strtoi is a wrapper of strconv.Atoi().
// If strconv.Atoi() returns an error, Strtoi calls panic.
func Strtoi(s string) int {
	if i, err := strconv.Atoi(s); err != nil {
		panic(errors.New("[argument error]: Strtoi only accepts integer string"))
	} else {
		return i
	}
}

// PrintIntsLine returns integers string delimited by a space.
func PrintIntsLine(A ...int) string {
	res := []rune{}

	for i := 0; i < len(A); i++ {
		str := strconv.Itoa(A[i])
		res = append(res, []rune(str)...)

		if i != len(A)-1 {
			res = append(res, ' ')
		}
	}

	return string(res)
}

// PrintIntsLine returns integers string delimited by a space.
func PrintInts64Line(A ...int64) string {
	res := []rune{}

	for i := 0; i < len(A); i++ {
		str := strconv.FormatInt(A[i], 10) // 64bit int version
		res = append(res, []rune(str)...)

		if i != len(A)-1 {
			res = append(res, ' ')
		}
	}

	return string(res)
}

// PrintfDebug is wrapper of fmt.Fprintf(os.Stderr, format, a...)
func PrintfDebug(format string, a ...interface{}) {
	fmt.Fprintf(os.Stderr, format, a...)
}

// PrintfBufStdout is function for output strings to buffered os.Stdout.
// You may have to call stdout.Flush() finally.
func PrintfBufStdout(format string, a ...interface{}) {
	fmt.Fprintf(stdout, format, a...)
}

/*
URL:
https://codeforces.com/problemset/problem/1367/D
*/

package main

import (
	"bufio"
	"errors"
	"fmt"
	"io"
	"math"
	"os"
	"strconv"
)

/********** FAU standard libraries **********/

//fmt.Sprintf("%b\n", 255) 	// binary expression

/********** I/O usage **********/

//str := ReadString()
//i := ReadInt()
//X := ReadIntSlice(n)
//S := ReadRuneSlice()
//a := ReadFloat64()
//A := ReadFloat64Slice(n)

//str := ZeroPaddingRuneSlice(num, 32)
//str := PrintIntsLine(X...)

/*******************************************************************/

const (
	// General purpose
	MOD          = 1000000000 + 7
	ALPHABET_NUM = 26
	INF_INT64    = math.MaxInt64
	INF_BIT60    = 1 << 60
	INF_INT32    = math.MaxInt32
	INF_BIT30    = 1 << 30
	NIL          = -1

	// for dijkstra, prim, and so on
	WHITE = 0
	GRAY  = 1
	BLACK = 2
)

func init() {
	// bufio.ScanWords <---> bufio.ScanLines
	ReadString = newReadString(os.Stdin, bufio.ScanWords)
	stdout = bufio.NewWriter(os.Stdout)
}

var (
	q int

	S []rune
	m int
	B []int

	memo []int
	nums [50]int
)

func main() {
	q = ReadInt()
	for i := 0; i < q; i++ {
		S = ReadRuneSlice()
		m = ReadInt()
		B = ReadIntSlice(m)

		solve()
	}
}

func solve() {
	nums = [50]int{}
	for _, r := range S {
		nums[r-'a']++
	}

	memo = make([]int, m)
	answers := make([]rune, m)

	for !isComplete(memo) {
		var c rune

		target := findZero(B, memo)
		for r := 'z'; r >= 'a'; r-- {
			if nums[r-'a'] >= len(target) {
				nums[r-'a'] = 0
				c = r
				break
			}
		}

		fix(B, memo, answers, c)
		decrease(B, target)
	}

	fmt.Println(string(answers))
}

func decrease(B, target []int) {
	for _, t := range target {
		for i := 0; i < m; i++ {
			if B[i] > 0 {
				d := AbsInt(i - t)
				B[i] -= d
			}
		}
	}
}

// AbsInt is integer version of math.Abs
func AbsInt(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

func fix(B, memo []int, answers []rune, c rune) {
	for i := 0; i < len(B); i++ {
		if B[i] == 0 && memo[i] == 0 {
			memo[i] = 1
			answers[i] = c
		}
	}
}

func findZero(B, memo []int) []int {
	res := []int{}

	for i, b := range B {
		if b == 0 && memo[i] != 1 {
			res = append(res, i)
		}
	}

	return res
}

func isComplete(memo []int) bool {
	for _, a := range memo {
		if a == 0 {
			return false
		}
	}
	return true
}

/*******************************************************************/

/*********** I/O ***********/

var (
	// ReadString returns a WORD string.
	ReadString func() string
	stdout     *bufio.Writer
)

func newReadString(ior io.Reader, sf bufio.SplitFunc) func() string {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+9)) // for Codeforces
	r.Split(sf)

	return func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
}

// ReadInt returns an integer.
func ReadInt() int {
	return int(readInt64())
}
func ReadInt2() (int, int) {
	return int(readInt64()), int(readInt64())
}
func ReadInt3() (int, int, int) {
	return int(readInt64()), int(readInt64()), int(readInt64())
}
func ReadInt4() (int, int, int, int) {
	return int(readInt64()), int(readInt64()), int(readInt64()), int(readInt64())
}

// ReadInt64 returns as integer as int64.
func ReadInt64() int64 {
	return readInt64()
}
func ReadInt64_2() (int64, int64) {
	return readInt64(), readInt64()
}
func ReadInt64_3() (int64, int64, int64) {
	return readInt64(), readInt64(), readInt64()
}
func ReadInt64_4() (int64, int64, int64, int64) {
	return readInt64(), readInt64(), readInt64(), readInt64()
}

func readInt64() int64 {
	i, err := strconv.ParseInt(ReadString(), 0, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

// ReadIntSlice returns an integer slice that has n integers.
func ReadIntSlice(n int) []int {
	b := make([]int, n)
	for i := 0; i < n; i++ {
		b[i] = ReadInt()
	}
	return b
}

// ReadInt64Slice returns as int64 slice that has n integers.
func ReadInt64Slice(n int) []int64 {
	b := make([]int64, n)
	for i := 0; i < n; i++ {
		b[i] = ReadInt64()
	}
	return b
}

// ReadFloat64 returns an float64.
func ReadFloat64() float64 {
	return float64(readFloat64())
}

func readFloat64() float64 {
	f, err := strconv.ParseFloat(ReadString(), 64)
	if err != nil {
		panic(err.Error())
	}
	return f
}

// ReadFloatSlice returns an float64 slice that has n float64.
func ReadFloat64Slice(n int) []float64 {
	b := make([]float64, n)
	for i := 0; i < n; i++ {
		b[i] = ReadFloat64()
	}
	return b
}

// ReadRuneSlice returns a rune slice.
func ReadRuneSlice() []rune {
	return []rune(ReadString())
}

/*********** Debugging ***********/

// ZeroPaddingRuneSlice returns binary expressions of integer n with zero padding.
// For debugging use.
func ZeroPaddingRuneSlice(n, digitsNum int) []rune {
	sn := fmt.Sprintf("%b", n)

	residualLength := digitsNum - len(sn)
	if residualLength <= 0 {
		return []rune(sn)
	}

	zeros := make([]rune, residualLength)
	for i := 0; i < len(zeros); i++ {
		zeros[i] = '0'
	}

	res := []rune{}
	res = append(res, zeros...)
	res = append(res, []rune(sn)...)

	return res
}

// Strtoi is a wrapper of strconv.Atoi().
// If strconv.Atoi() returns an error, Strtoi calls panic.
func Strtoi(s string) int {
	if i, err := strconv.Atoi(s); err != nil {
		panic(errors.New("[argument error]: Strtoi only accepts integer string"))
	} else {
		return i
	}
}

// PrintIntsLine returns integers string delimited by a space.
func PrintIntsLine(A ...int) string {
	res := []rune{}

	for i := 0; i < len(A); i++ {
		str := strconv.Itoa(A[i])
		res = append(res, []rune(str)...)

		if i != len(A)-1 {
			res = append(res, ' ')
		}
	}

	return string(res)
}

// PrintIntsLine returns integers string delimited by a space.
func PrintInts64Line(A ...int64) string {
	res := []rune{}

	for i := 0; i < len(A); i++ {
		str := strconv.FormatInt(A[i], 10) // 64bit int version
		res = append(res, []rune(str)...)

		if i != len(A)-1 {
			res = append(res, ' ')
		}
	}

	return string(res)
}

// PrintfDebug is wrapper of fmt.Fprintf(os.Stderr, format, a...)
func PrintfDebug(format string, a ...interface{}) {
	fmt.Fprintf(os.Stderr, format, a...)
}

// PrintfBufStdout is function for output strings to buffered os.Stdout.
// You may have to call stdout.Flush() finally.
func PrintfBufStdout(format string, a ...interface{}) {
	fmt.Fprintf(stdout, format, a...)
}

package main

import (
	"bufio"
	"fmt"
	"os"
)

var nTest, n int
var a [55]int
var s string

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)

	fmt.Fscan(in, &nTest)
	for t := 0; t < nTest; t++ {
		fmt.Fscan(in, &s, &n)
		var res [55]int
		cnt := map[int]int{}
		for i := 0; i < len(s); i++ {
			cnt[int(s[i])]++
		}

		for i := 0; i < n; i++ {
			fmt.Fscan(in, &a[i])
		}

		fill := 0
		for fill != n {
			zero := []int{}
			for i := 0; i < n; i++ {
				if a[i] == 0 && res[i] == 0 {
					zero = append(zero, i)
				}
			}
			char := int('z')
			for cnt[char] < len(zero) {
				char--
			}
			cnt[char] -= len(zero)
			fill += len(zero)
			for j := 0; j < len(zero); j++ {
				res[zero[j]] = char
				for k := 0; k < n; k++ {
					if a[k] != 0 {
						if zero[j] > k {
							a[k] -= zero[j] - k
						} else {
							a[k] -= k - zero[j]
						}
					}
				}
			}
		}

		for i := 0; i < n; i++ {
			fmt.Fprintf(out, "%c", res[i])
		}
		fmt.Fprintln(out)
	}

	out.Flush()
}

package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
)

var nTest, n int
var a [55]int
var s string

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)

	fmt.Fscan(in, &nTest)
	for t := 0; t < nTest; t++ {
		fmt.Fscan(in, &s, &n)
		var res [55]int
		chars := []int{}
		used := map[int]bool{}
		for i := 0; i < len(s); i++ {
			chars = append(chars, int(s[i]))
		}

		sort.Slice(chars, func(i, j int) bool {
			return chars[i] > chars[j]
		})

		for i := 0; i < n; i++ {
			fmt.Fscan(in, &a[i])
		}

		fill := 0
		charsID := 0
		for fill != n {
			zero := []int{}
			for i := 0; i < n; i++ {
				if a[i] == 0 && res[i] == 0 {
					zero = append(zero, i)
				}
			}

			for j := 0; j < len(zero); j++ {
				for used[chars[charsID]] {
					charsID++
				}
				res[zero[j]] = chars[charsID]
				fill++
				charsID++
				for k := 0; k < n; k++ {
					if a[k] != 0 {
						if zero[j] > k {
							a[k] -= zero[j] - k
						} else {
							a[k] -= k - zero[j]
						}
					}
				}
			}
			for j := 0; j < len(zero); j++ {
				used[res[zero[j]]] = true
			}
		}

		for i := 0; i < n; i++ {
			fmt.Fprintf(out, "%c", res[i])
		}
		fmt.Fprintln(out)
	}

	out.Flush()
}


package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)
var wrtr = bufio.NewWriterSize(os.Stdout, 10_000_000)
var rdr = bufio.NewScanner(os.Stdin)
func gs() string  { rdr.Scan(); return rdr.Text() }
func gi() int     { i,e := strconv.Atoi(gs()); if e != nil {panic(e)}; return i }
func gi2() (int,int) { return gi(),gi() }
func gi3() (int,int,int) { return gi(),gi(),gi() }
func gi4() (int,int,int,int) { return gi(),gi(),gi(),gi() }
func gis(n int) []int  { res := make([]int,n); for i:=0;i<n;i++ { res[i] = gi() }; return res }
func gf() float64 { f,e := strconv.ParseFloat(gs(),64); if e != nil {panic(e)}; return f }
func gbs() []byte { return []byte(gs()) }
func gfs(n int) []float64  { res := make([]float64,n); for i:=0;i<n;i++ { res[i] = gf() }; return res }
func gss(n int) []string  { res := make([]string,n); for i:=0;i<n;i++ { res[i] = gs() }; return res }
func ia(m int) []int { return make([]int,m) }
func iai(m int,v int) []int { a := make([]int,m); for i:=0;i<m;i++ { a[i] = v }; return a }
func twodi(n int,m int,v int) [][]int {
	r := make([][]int,n); for i:=0;i<n;i++ { x := make([]int,m); for j:=0;j<m;j++ { x[j] = v }; r[i] = x }; return r
}
func fill2(m int) ([]int,[]int) { a,b := ia(m),ia(m); for i:=0;i<m;i++ {a[i],b[i] = gi(),gi()}; return a,b }
func fill3(m int) ([]int,[]int,[]int) { a,b,c := ia(m),ia(m),ia(m); for i:=0;i<m;i++ {a[i],b[i],c[i] = gi(),gi(),gi()}; return a,b,c }
func fill4(m int) ([]int,[]int,[]int,[]int) { a,b,c,d := ia(m),ia(m),ia(m),ia(m); for i:=0;i<m;i++ {a[i],b[i],c[i],d[i] = gi(),gi(),gi(),gi()}; return a,b,c,d }
func abs(a int) int { if a < 0 { return -a }; return a }
func rev(a []int) { i,j := 0,len(a)-1; for i < j { a[i],a[j] = a[j],a[i]; i++; j-- } }
func max(a,b int) int { if a > b { return a }; return b }
func min(a,b int) int { if a > b { return b }; return a }
func tern(cond bool, a int, b int) int { if cond { return a }; return b }
func terns(cond bool, a string, b string) string { if cond { return a }; return b }
func maxarr(a []int) int { ans := a[0]; for _,aa := range(a) { if aa > ans { ans = aa } }; return ans }
func minarr(a []int) int { ans := a[0]; for _,aa := range(a) { if aa < ans { ans = aa } }; return ans }
func sumarr(a []int) int { ans := 0; for _,aa := range(a) { ans += aa }; return ans }
func zeroarr(a []int) { for i:=0; i<len(a); i++ { a[i] = 0 } }
func powmod(a,e,mod int) int { res, m := 1, a; for e > 0 { if e&1 != 0 { res = res * m % mod }; m = m * m % mod; e >>= 1 }; return res }
func powint(a,e int) int { res, m := 1, a; for e > 0 { if e&1 != 0 { res = res * m }; m = m * m; e >>= 1 }; return res }
func gcd(a,b int) int { for b != 0 { t:=b; b=a%b; a=t }; return a }
func gcdExtended(a,b int) (int,int,int) { if a == 0 { return b,0,1 }; gcd,x1,y1 := gcdExtended(b%a,a); return gcd, y1-(b/a)*x1,x1 }
func modinv(a,m int) (int,bool) { g,x,_ := gcdExtended(a,m); if g != 1 { return 0,false }; return (x % m + m) % m,true  }
func makefact(n int,mod int) ([]int,[]int) {
	fact,factinv := make([]int,n+1),make([]int,n+1)
	fact[0] = 1; for i:=1;i<=n;i++ { fact[i] = fact[i-1] * i % mod }
	factinv[n] = powmod(fact[n],mod-2,mod); for i:=n-1;i>=0;i-- { factinv[i] = factinv[i+1] * (i+1) % mod }
	return fact,factinv
}
func vecintstring(a []int) string { astr := make([]string,len(a)); for i,a := range a { astr[i] = strconv.Itoa(a) }; return strings.Join(astr," ") }
func main() {
	//f1, _ := os.Create("cpu.prof"); pprof.StartCPUProfile(f1); defer pprof.StopCPUProfile()
	defer wrtr.Flush()
	infn := ""; if infn == "" && len(os.Args) > 1 {	infn = os.Args[1] }
	if infn != "" {	f, e := os.Open(infn); if e != nil { panic(e) }; rdr = bufio.NewScanner(f) }
	rdr.Split(bufio.ScanWords); rdr.Buffer(make([]byte,1024),1_000_000_000)
	// PROGRAM STARTS HERE
	T := gi()
	type pi struct {l,r int }
	for tt:=1;tt<=T;tt++ {
		N := gi(); S := gs(); edges := make([]pi,0,N-1)
		cnt0,cnt1 := 0,0
		for _,c := range S { if c == '0' { cnt0++ } else { cnt1++ } }
		if cnt1 == 0 || cnt1 % 2 == 1 { fmt.Fprintln(wrtr,"NO"); continue }
		// Make the start of the chain
		f1,l1 := 0,N-1; for S[f1] == '0' { f1++ }; for S[l1] == '0' { l1-- }
		for i:=0;i<f1;i++   { edges = append(edges,pi{i,i+1}) }
		for i:=N-1;i>l1;i-- { edges = append(edges,pi{i,i-1}) }
		masterChain := []int{0}
		idx := f1+1
		for idx < l1 {
			if S[idx] == '0' { masterChain = append(masterChain,idx); idx++; continue }
			// Now do a 1 --- chain of 0s --- 1
			edges = append(edges,pi{idx,idx+1});  idx++
			for S[idx] == '0' { edges = append(edges,pi{idx,idx+1});  idx++ }
			masterChain = append(masterChain,idx); idx++
		}
		masterChain = append(masterChain,N-1)
		for i:=0;i<len(masterChain)-1;i++ {
			edges = append(edges,pi{masterChain[i],masterChain[i+1]})
		}
		fmt.Fprintln(wrtr,"YES")
		for _,e := range edges { fmt.Fprintf(wrtr,"%v %v\n",e.l+1,e.r+1) }
	}
}

package main

import (
	"bufio"
	. "fmt"
	"os"
)

func Solve() {
	n := ri()
	var s string
	scan(&s)
	cnt := 0
	for i := 0; i < n; i++ {
		if s[i] == '1' {
			cnt++
		}
	}
	if cnt%2 == 1 || cnt == 0 {
		println("NO")
		return
	}
	println("YES")
	type pair struct{ l, r int }
	var p []pair
	for i := 0; i < n; i++ {
		if s[i] == '0' {
			continue
		}
		j := i + 1
		for s[j] == '0' {
			j++
		}
		p = append(p, pair{i, j})
		i = j
	}
	var a []int
	for i := 0; i < n; i++ {
		a = append(a, i)
	}
	for i := 0; i < len(p)-1; i++ {
		for j := p[i].l; j < p[i].r; j++ {
			println(j+1, j+2)
			a[j], a[j+1] = p[i].l, p[i].l
		}
	}
	var b []int
	b = append(b, a[0])
	for i := 1; i < n; i++ {
		if a[i] != a[i-1] {
			b = append(b, a[i])
		}
	}
	st, ed := p[len(p)-1].l, p[len(p)-1].r
	l, r := 0, 0
	for b[l] != st {
		l++
	}
	for b[r] != ed {
		r++
	}
	n = len(b)
	switch {
	case l == 0 && r == n-1:
		for i := 0; i < r; i++ {
			println(b[i]+1, b[i+1]+1)
		}
	case l+1 == r:
		for i := r; i != l; i = (i + 1) % n {
			println(b[i]+1, b[(i+1)%n]+1)
		}
	default:
		for i := l; i < r-1; i++ {
			println(b[i]+1, b[i+1]+1)
		}
		println(b[r-1]+1, b[(l-1+n)%n]+1)
		for i := (l - 1 + n) % n; i != r; i = (i - 1 + n) % n {
			println(b[i]+1, b[(i-1+n)%n]+1)
		}
	}
}

func main() {
	T := 0
	in, out = bufio.NewReader(os.Stdin), bufio.NewWriter(os.Stdout)
	if T == 0 {
		scan(&T)
	}
	for t := 0; t < T; t++ {
		Solve()
	}
	out.Flush()
}

var in *bufio.Reader
var out *bufio.Writer

//===================================IO区===================================

//ri() 将直接读入并返回一个 int
func ri() (x int) {
	scan(&x)
	return x
}

//scan() 用法与 fmt.scan() 相似，可以传入多个变量的地址进行读入操作
func scan(a ...interface{}) { Fscan(in, a...) }

func print(a ...interface{}) { Fprint(out, a...) }

func println(a ...interface{}) { Fprintln(out, a...) }

//===================================IO区===================================

//===================================基础区===================================

func min(a ...int) int {
	ans := a[0]
	for i := 1; i < len(a); i++ {
		if a[i] < ans {
			ans = a[i]
		}
	}
	return ans
}

func max(a ...int) int {
	ans := a[0]
	for i := 1; i < len(a); i++ {
		if a[i] > ans {
			ans = a[i]
		}
	}
	return ans
}

//===================================基础区===================================


package main

import (
	"bufio"
	"fmt"
	"os"
)

func main() {
	r := bufio.NewReader(os.Stdin)
	w := bufio.NewWriter(os.Stdout)
	defer w.Flush()

	var t int
	fmt.Fscan(r, &t)

	for i := 0; i < t; i++ {
		var a, b, c, d int
		fmt.Fscan(r, &a, &b, &c, &d)

		fmt.Fprintln(w, b, c, c)

	}
}

package main

import (
	"bufio"
	"fmt"
	"os"
)

func main() {
	var t, a, b, c, d int
	in := bufio.NewReader(os.Stdin)
	fmt.Fscan(in, &t)
	for i := 0; i < t; i++ {
		fmt.Fscan(in, &a, &b, &c, &d)
		fmt.Println(b, c, c)
	}
}

package main

import (
	"bufio"
	"fmt"
	"os"
)

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var t int
	fmt.Fscan(in, &t)
	for ; t > 0; t-- {
		var a, b, c, d uint64
		fmt.Fscan(in, &a, &b, &c, &d)
		fmt.Fprintln(out, b, c, c)
	}
}

package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

var reader = bufio.NewReader(os.Stdin)
var writer = bufio.NewWriter(os.Stdout)

func printf(f string, a ...interface{}) { fmt.Fprintf(writer, f, a...) }
func scanf(f string, a ...interface{})  { fmt.Fscanf(reader, f, a...) }
func scanIntArr() ([]int, error) {
	str, err := reader.ReadString('\n')
	if err != nil {
		return nil, err
	}
	str = strings.TrimRight(str, "\n\r")
	strArr := strings.Split(str, " ")

	arr := make([]int, len(strArr))
	for i, strA := range strArr {
		arr[i], err = strconv.Atoi(strA)
		if err != nil {
			return nil, err
		}
	}

	return arr, nil
}

func main() {
	defer writer.Flush()

	var t int
	scanf("%d\n", &t)

	for i := 0; i < t; i++ {
		exec()
	}
}

func exec() {
	var a, b, c, d uint64
	scanf("%d %d %d %d\n", &a, &b, &c, &d)

	printf("%d %d %d\n", b, c, c)
}

package main

import "fmt"

func main() {
    var t int
    fmt.Scanln(&t)
    for i:=1; i<=t; i++ {
        var a, b, c, d int64
        fmt.Scanln(&a, &b, &c, &d)
        fmt.Println(b, c, c)
    }
}

// @problemURL url.com
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func nt(s *bufio.Scanner) string {
	s.Scan()
	return s.Text()
}

func ni(s *bufio.Scanner) int {
	return atoi(nt(s))
}

func atoi(s string) int {
	i, err := strconv.Atoi(s)
	if err != nil {
		panic(err)
	}
	return i
}

func main() {
	var in = bufio.NewReader(os.Stdin)
	s := bufio.NewScanner(in)
	s.Split(bufio.ScanWords)

	// Code
	for T := ni(s); T > 0; T-- {
		_, b, c, _ := ni(s), ni(s), ni(s), ni(s)
		fmt.Println(b, c, c)

	}
}

package main

import(
	"fmt"
)

func main() {
	var T int
	fmt.Scan(&T)

	for t := 0; t < T; t++ {
		var a, b, c, d int
		fmt.Scan(&a, &b, &c, &d)
		fmt.Printf("%d %d %d\n", b, c, c)
	}
}

// http://acm.timus.ru/problem.aspx?space=1&num=1741
package main

import (
	"fmt"
	"bufio"
	"os"
)

// (c) Dmitriy Blokhin (sv.dblokhin@gmail.com)

func main () {
	var (
		T int
	)

	//f, _ := os.Open("input.txt")
	//input := bufio.NewReader(f)
	input := bufio.NewReader(os.Stdin)

	fmt.Fscanln(input, &T)

	for i := 0; i < T; i++ {
		var a, b, c, d int
		fmt.Fscan(input, &a, &b, &c, &d)
		x, y, z := solve(a, b, c, d)
		fmt.Println(x, y, z)
	}
}

func solve(a, b, c, d int) (x, y, z int) {
	x, y = a, b
	gA, gB := b - a, c - b
	if x + y > c {
		return x, y, c
	}

	need := c - x - y + 1
	if gA >= need {
		return a + need, b, c
	}

	if gB >= need {
		return a, b + need, c
	}

	return a + gA, b + need - gA, z
}

package main

import (
	"bufio"
	"fmt"
	"os"
)

func min(a int, b int) int {
	if a < b {
		return a
	}
	return b
}

func max(a int, b int) int {
	if a > b {
		return a
	}
	return b
}

func main() {
	rd := bufio.NewReader(os.Stdin)
	wr := bufio.NewWriter(os.Stdout)

	var t, a, b, c, d, x, y, z, i int
	var bo bool
	fmt.Fscanf(rd, "%d\n", &t)

	for i = 0; i < t; i++ {
		fmt.Fscanf(rd, "%d %d %d %d\n", &a, &b, &c, &d)
		bo = false
		for x = a; x <= b; x++ {
			for y = max(b, c-x+1); y <= c; y++ {
				for z = c; z <= min(x+y-1, d); z++ {
					bo = x+y > z
					if bo {
						fmt.Fprintf(wr, "%d %d %d\n", x, y, z)
						break
					}
				}
				if bo {
					break
				}
			}
			if bo {
				break
			}
		}
	}

	wr.Flush()
}

package main

import (
	"bufio"
	. "fmt"
	"io"
	"os"
)

// github.com/EndlessCheng/codeforces-go
func run(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()

	solve := func(_case int) {
		var a,b,c,d int
		Fscan(in, &a, &b, &c, &d)
		Fprintln(out, b, c, c)
	}

	var t int
	Fscan(in, &t)
	for _case := 1; _case <= t; _case++ {
		solve(_case)
	}
}

func main() { run(os.Stdin, os.Stdout) }

package main

import "fmt"

func main() {
	var testNum int
	fmt.Scanln(&testNum)
	for i := 0; i<testNum; i++{
		triangler()
	}

}

func triangler(){
	var a,b,c,d int
	fmt.Scanln(&a,&b,&c,&d)
	fmt.Println(b,c,c)
}

package main

import (
	"fmt"
)

func main() {
	var t int
	fmt.Scan(&t)
	for i := 0; i < t; i++ {
		var a, b, c, d int
		fmt.Scan(&a, &b, &c, &d)
		fmt.Println(b, c, c)
	}
}

package main

import "fmt"

func main() {
	var t, a, b, c, d int
	fmt.Scan(&t)
	for i := 0; i < t; i++ {
		fmt.Scan(&a, &b, &c, &d)
		fmt.Println(a, c, c)
	}
}

package main

import (
	"fmt"
)

func minVal(a, b int) int {
	if a <= b {
		return a
	}
	return b
}

func maxVal(a, b int) int {
	if a >= b {
		return a
	}
	return b
}

func max(arr []int) (max int) {
	max = arr[0]
	for _, val := range arr {
		if val > max {
			max = val
		}
	}
	return max
}

func main() {
	var t int
	fmt.Scan(&t)
	for qt := 0; qt < t; qt++ {
		var a, b, c, d int
		fmt.Scan(&a, &b, &c, &d)
		x := b
		y := c
		z := c
		fmt.Println(x, y, z)
	}
}

package main
import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func newScanner() *bufio.Scanner {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	return scanner
}

func scanInt() int {
	sc.Scan()
	v, _ := strconv.Atoi(sc.Text())
	return v
}

func scanInts(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = scanInt()
	}
	return a
}

func scanString() string {
	if sc.Scan() {
		return sc.Text()
	}
	panic(sc.Err())
}

var sc = newScanner()

func main() {
	for t:= scanInt(); t > 0 ; t-- {
		_, b, c, _  := scanInt(), scanInt(), scanInt(), scanInt()
		fmt.Println(b, c, c)
	}
}

package main

import (
	. "fmt"
)

func main() {
	var t int64
	Scan(&t)
	for i := int64(0); i < t; i++ {
		var a, b, c, d int64
		Scan(&a, &b, &c, &d)
		Println(b, c, c)
	}
}

package main

import (
	"bufio"
	. "fmt"
	"os"
	"strconv"
	"strings"
)

var reader *bufio.Reader

func input() string {
	text, _ := reader.ReadString('\n');
	return text[:len(text) - 1]
}

func inputI64() int64 {
	line := input()
	r, _ := strconv.ParseInt(line, 10, 64)
	return r
}

func i64(vars... *int64) {
	i := input()
	s := strings.Split(i, " ")
	for i, str := range s {
		*vars[i], _ = strconv.ParseInt(str, 10, 64)
	}
}

func main() {
	reader = bufio.NewReader(os.Stdin)
	solution()
}

func solution() {
	var t int64
	Scan(&t)
	for i := int64(0); i < t; i++ {
		var a, b, c, d int64
		Scan(&a, &b, &c, &d)
		Println(b, c, c)
	}
}

package main

import (
    "bufio"
    "fmt"
    "io"
    "os"
)

type BufferedWriter interface {
    Printf(format string, a ...interface{})
    Flush()
}

type writerImpl struct {
    *bufio.Writer
}

func NewBufferedWriter(writer io.Writer) BufferedWriter {
    return &writerImpl{Writer: bufio.NewWriter(writer)}
}

func (impl *writerImpl) Printf(f string, a ...interface{}) {
    fmt.Fprintf(impl.Writer, f, a...)
}

func (impl *writerImpl) Flush() {
    impl.Writer.Flush()
}

type WordScanner interface {
    NextInt() int
    NextInt64() int64
    NextString() string
}

type wordScannerImpl struct {
    *bufio.Scanner
}

func NewWordScanner(reader io.Reader) WordScanner {
    s := bufio.NewScanner(reader)
    s.Split(bufio.ScanWords)
    // adjust the following size as needed
    // 2 << 17 is good enough to scan strings of len 2*10^5
    // it could go as high as 2 << 26 before cf judge breaks
    size := 2 << 20
    buf := make([]byte, size)
    s.Buffer(buf, size)
    return &wordScannerImpl{Scanner: s}
}

func (impl *wordScannerImpl) NextInt() int {
    impl.Scan()
    bb := impl.Bytes()
    i := 0
    if bb[0] == '-' {
        for _, b := range bb[1:] {
            i *= 10
            i -= int(b - '0')
        }
        return i
    }
    for _, b := range bb {
        i *= 10
        i += int(b - '0')
    }
    return i
}

func (impl *wordScannerImpl) NextInt64() int64 {
    impl.Scan()
    bb := impl.Bytes()
    i := int64(0)
    if bb[0] == '-' {
        for _, b := range bb[1:] {
            i *= 10
            i -= int64(b - '0')
        }
        return i
    }
    for _, b := range bb {
        i *= 10
        i += int64(b - '0')
    }
    return i
}

func (impl *wordScannerImpl) NextString() string {
    impl.Scan()
    return impl.Text()
}

var reader = NewWordScanner(os.Stdin)
var writer = NewBufferedWriter(os.Stdout)

func main() {
    defer writer.Flush()
    t := reader.NextInt64()
    for ; t > 0; t-- {
        a, _, c, _ := reader.NextInt64(), reader.NextInt64(), reader.NextInt64(), reader.NextInt64()
        writer.Printf("%d %d %d\n", a, c, c)
    }
}

package main

import (
	"bufio"
	"fmt"
	"os"
)

func main() {
	var t, a, b, c, d int
	in := bufio.NewReader(os.Stdin)
	fmt.Fscan(in, &t)
	for i := 0; i < t; i++ {
		fmt.Fscan(in, &a, &b, &c, &d)
		fmt.Println(c, c, b)
	}
}

package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

var reader = bufio.NewReader(os.Stdin)
var writer = bufio.NewWriter(os.Stdout)

func printf(f string, a ...interface{}) { fmt.Fprintf(writer, f, a...) }
func scanf(f string, a ...interface{})  { fmt.Fscanf(reader, f, a...) }
func scanIntArr() ([]int, error) {
	str, err := reader.ReadString('\n')
	if err != nil {
		return nil, err
	}
	str = strings.TrimRight(str, "\n\r")
	strArr := strings.Split(str, " ")

	arr := make([]int, len(strArr))
	for i, strA := range strArr {
		arr[i], err = strconv.Atoi(strA)
		if err != nil {
			return nil, err
		}
	}

	return arr, nil
}

func main() {
	defer writer.Flush()

	var t int
	scanf("%d\n", &t)

	for i := 0; i < t; i++ {
		exec()
	}
}

func exec() {
	var a, b, c, d uint64
	scanf("%d %d %d %d\n", &a, &b, &c, &d)

	if b == c {
		printf("%d %d %d\n", b-1, c, c+1)
		return
	}
	printf("%d %d %d\n", b, c, c)
}

package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

var reader = bufio.NewReader(os.Stdin)
var writer = bufio.NewWriter(os.Stdout)

func printf(f string, a ...interface{}) { fmt.Fprintf(writer, f, a...) }
func scanf(f string, a ...interface{})  { fmt.Fscanf(reader, f, a...) }
func scanIntArr() ([]int, error) {
	str, err := reader.ReadString('\n')
	if err != nil {
		return nil, err
	}
	str = strings.TrimRight(str, "\n\r")
	strArr := strings.Split(str, " ")

	arr := make([]int, len(strArr))
	for i, strA := range strArr {
		arr[i], err = strconv.Atoi(strA)
		if err != nil {
			return nil, err
		}
	}

	return arr, nil
}

func main() {
	defer writer.Flush()

	var t int
	scanf("%d\n", &t)

	for i := 0; i < t; i++ {
		exec()
	}
}

func exec() {
	var a, b, c, d uint64
	scanf("%d %d %d %d\n", &a, &b, &c, &d)

	var x, y, z uint64
	if a == b {
		x = b
	} else {
		x = b - 1
	}
	y = c
	if c == d {
		z = c
	} else {
		z = c + 1
	}

	printf("%d %d %d\n", x, y, z)
}

package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

var reader = bufio.NewReader(os.Stdin)
var writer = bufio.NewWriter(os.Stdout)

func printf(f string, a ...interface{}) { fmt.Fprintf(writer, f, a...) }
func scanf(f string, a ...interface{})  { fmt.Fscanf(reader, f, a...) }
func scanIntArr() ([]int, error) {
	str, err := reader.ReadString('\n')
	if err != nil {
		return nil, err
	}
	str = strings.TrimRight(str, "\n\r")
	strArr := strings.Split(str, " ")

	arr := make([]int, len(strArr))
	for i, strA := range strArr {
		arr[i], err = strconv.Atoi(strA)
		if err != nil {
			return nil, err
		}
	}

	return arr, nil
}

func main() {
	defer writer.Flush()

	var t int
	scanf("%d\n", &t)

	for i := 0; i < t; i++ {
		exec()
	}
}

func exec() {
	var a, b, c, d uint64
	scanf("%d %d %d %d\n", &a, &b, &c, &d)

	if b == c {
		printf("%d %d %d\n", b-1, c, c+1)
		return
	}
	printf("%d %d %d\n", b, c-1, c)
}

// @problemURL url.com
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func nt(s *bufio.Scanner) string {
	s.Scan()
	return s.Text()
}

func ni(s *bufio.Scanner) int {
	return atoi(nt(s))
}

func atoi(s string) int {
	i, err := strconv.Atoi(s)
	if err != nil {
		panic(err)
	}
	return i
}

func main() {
	var in = bufio.NewReader(os.Stdin)
	s := bufio.NewScanner(in)
	s.Split(bufio.ScanWords)

	// Code
	for T := ni(s); T > 0; T-- {
		_, b, c, d := ni(s), ni(s), ni(s), ni(s)

		x := b
		y := c
		z := d

		fmt.Println(x, y, z)
	}
}

package main

import(
	"fmt"
)

func main() {
	var T int
	fmt.Scanf("%d", &T)

	for t := 0; t < T; t++ {
		var a, b, c, d int
		fmt.Scanf("%d %d %d %d", &a, &b, &c, &d)
		fmt.Printf("%d %d %d\n", b, c, c)
	}
}

package main

import (
	"bufio"
	"fmt"
	"os"
)

func min(a int, b int) int {
	if a < b {
		return a
	}
	return b
}

func main() {
	rd := bufio.NewReader(os.Stdin)
	wr := bufio.NewWriter(os.Stdout)

	var t, a, b, c, d, x, y, z, i int
	var bo bool
	fmt.Fscanf(rd, "%d\n", &t)

	for i = 0; i < t; i++ {
		fmt.Fscanf(rd, "%d %d %d %d\n", &a, &b, &c, &d)
		bo = false
		for x = a; x <= b; x++ {
			for y = c - x + 1; y <= c; y++ {
				for z = c; z <= min(x+y-1, d); z++ {
					bo = x+y > z
					if bo {
						fmt.Fprintf(wr, "%d %d %d\n", x, y, z)
						break
					}
				}
				if bo {
					break
				}
			}
			if bo {
				break
			}
		}
	}

	wr.Flush()
}

package main

import (
	"bufio"
	. "fmt"
	"os"
	"strconv"
	"strings"
)

var reader *bufio.Reader

func input() string {
	text, _ := reader.ReadString('\n');
	return text[:len(text) - 1]
}

func inputI64() int64 {
	line := input()
	r, _ := strconv.ParseInt(line, 10, 64)
	return r
}

func i64(vars... *int64) {
	i := input()
	s := strings.Split(i, " ")
	for i, str := range s {
		*vars[i], _ = strconv.ParseInt(str, 10, 64)
	}
}

func main() {
	reader = bufio.NewReader(os.Stdin)
	solution()
}

func solution() {
	t := inputI64()
	for i := int64(0); i < t; i++ {
		var a, b, c, d int64
		Scan(&a, &b, &c, &d)
		Println(b, c, c)
	}
}

package main

import (
	"bufio"
	. "fmt"
	"os"
	"strconv"
	"strings"
)

var reader *bufio.Reader

func input() string {
	text, _ := reader.ReadString('\n');
	return text[:len(text) - 1]
}

func inputI64() int64 {
	line := input()
	r, _ := strconv.ParseInt(line, 10, 64)
	return r
}

func i64(vars... *int64) {
	i := input()
	s := strings.Split(i, " ")
	for i, str := range s {
		*vars[i], _ = strconv.ParseInt(str, 10, 64)
	}
}

func main() {
	reader = bufio.NewReader(os.Stdin)
	solution()
}

func solution() {
	text, _ := reader.ReadString('\n');
	t, _ := strconv.ParseInt(text[:len(text) - 1], 10, 64)
	for i := int64(0); i < t; i++ {
		var a, b, c, d int64
		Scan(&a, &b, &c, &d)
		Println(b, c, c)
	}
}

package main

import (
	"bufio"
	. "fmt"
	"os"
	"strconv"
	"strings"
)

var reader *bufio.Reader

func input() string {
	text, _ := reader.ReadString('\n');
	return text[:len(text) - 1]
}

func inputI64() int64 {
	line := input()
	r, _ := strconv.ParseInt(line, 10, 64)
	return r
}

func i64(vars... *int64) {
	i := input()
	s := strings.Split(i, " ")
	for i, str := range s {
		*vars[i], _ = strconv.ParseInt(str, 10, 64)
	}
}

func main() {
	reader = bufio.NewReader(os.Stdin)
        solution()
}

func solution() {
	t := inputI64()
	for i := int64(0); i < t; i++ {
		var a, b, c, d int64
		i64(&a, &b, &c, &d)
		Println(b, c, c)
	}
}

package main

import (
    "bufio"
    "fmt"
    "io"
    "os"
)

type BufferedWriter interface {
    Printf(format string, a ...interface{})
    Flush()
}

type writerImpl struct {
    *bufio.Writer
}

func NewBufferedWriter(writer io.Writer) BufferedWriter {
    return &writerImpl{Writer: bufio.NewWriter(writer)}
}

func (impl *writerImpl) Printf(f string, a ...interface{}) {
    fmt.Fprintf(impl.Writer, f, a...)
}

func (impl *writerImpl) Flush() {
    impl.Writer.Flush()
}

type WordScanner interface {
    NextInt() int
    NextInt64() int64
    NextString() string
}

type wordScannerImpl struct {
    *bufio.Scanner
}

func NewWordScanner(reader io.Reader) WordScanner {
    s := bufio.NewScanner(reader)
    s.Split(bufio.ScanWords)
    // adjust the following size as needed
    // 2 << 17 is good enough to scan strings of len 2*10^5
    // it could go as high as 2 << 26 before cf judge breaks
    size := 2 << 20
    buf := make([]byte, size)
    s.Buffer(buf, size)
    return &wordScannerImpl{Scanner: s}
}

func (impl *wordScannerImpl) NextInt() int {
    impl.Scan()
    bb := impl.Bytes()
    i := 0
    if bb[0] == '-' {
        for _, b := range bb[1:] {
            i *= 10
            i -= int(b - '0')
        }
        return i
    }
    for _, b := range bb {
        i *= 10
        i += int(b - '0')
    }
    return i
}

func (impl *wordScannerImpl) NextInt64() int64 {
    impl.Scan()
    bb := impl.Bytes()
    i := int64(0)
    if bb[0] == '-' {
        for _, b := range bb[1:] {
            i *= 10
            i -= int64(b - '0')
        }
        return i
    }
    for _, b := range bb {
        i *= 10
        i += int64(b - '0')
    }
    return i
}

func (impl *wordScannerImpl) NextString() string {
    impl.Scan()
    return impl.Text()
}

var reader = NewWordScanner(os.Stdin)
var writer = NewBufferedWriter(os.Stdout)

func main() {
    defer writer.Flush()
    t := reader.NextInt64()
    for ; t > 0; t-- {
        a, _, _, d := reader.NextInt64(), reader.NextInt64(), reader.NextInt64(), reader.NextInt64()
        writer.Printf("%d %d %d\n", a, d, d)
    }
}


package main

import "fmt"

func main() {
    var n,m int
    var s [55]string
    fmt.Scan(&n,&m)
    minrow, maxrow, mincol, maxcol := n-1, 0, m-1, 0
    for i := 0; i < n; i++ {
        fmt.Scan(&s[i])
        for j := 0; j < m; j++ {
            if s[i][j] == '*' {
                if minrow > i { minrow = i }
                if maxrow < i { maxrow = i }
                if mincol > j { mincol = j }
                if maxcol < j { maxcol = j }
            }
        }
    }
    for i := 0; i < n; i++ {
        if (i >= minrow) && (i <= maxrow) {
            for j := 0; j < m; j++ {
                if (j >= mincol) && (j <= maxcol) { fmt.Print(string(s[i][j])) }
            }
            fmt.Println()
        }
    }
}

package main

import "fmt"

func min(a, b int) int {
	if a < b {
		return a
	} else {
		return b
	}
}

func max(a, b int) int {
	if a > b {
		return a
	} else {
		return b
	}
}

func main() {
	var n, m int
	fmt.Scanf("%d %d\n", &n, &m)
	var grid = make([][]byte, n)
	for i := 0; i < n; i++ {
		grid[i] = make([]byte, m)
		fmt.Scanf("%s\n", &grid[i])
	}

	var minRow, minCol, maxRow, maxCol = 100, 100, 0, 0
	for i := 0; i < n; i++ {
		for j := 0; j < m; j++ {
			if grid[i][j] == '*' {
				minRow = min(minRow, i)
				minCol = min(minCol, j)
				maxRow = max(maxRow, i)
				maxCol = max(maxCol, j)
			}
		}
	}

	for i := minRow; i <= maxRow; i++ {
		for j := minCol; j <= maxCol; j++ {
			fmt.Printf("%c", grid[i][j])
		}
		fmt.Println()
	}
}

package main
import (
	"fmt"
	"bufio"
	"os"
	//"strconv"
)

func min(a,b int) int{
	if a<b {
		return a
	} else {
		return b
	}
}

func max(a,b int) int{
	if a>b {
		return a
	} else {
		return b
	}
}
func main() {
	var n,m int
	input:=bufio.NewScanner(os.Stdin)
	input.Split(bufio.ScanWords)
	fmt.Scan(&n,&m)
	x:=make([]string,n)
	l:=m
	r:=0
	u:=n
	d:=0
	for i:=0;i<n;i++ {
		input.Scan()
		x[i]=input.Text()
		for j:=0;j<m;j++ {
			if x[i][j]=='*' {
				l=min(j,l)
				r=max(j,r)
				u=min(i,u)
				d=max(i,d)
			}
		}
	}
	for i:=u;i<=d;i++ {
		for j:=l;j<=r;j++ {
			fmt.Print(string(x[i][j]))
		}
		fmt.Println()
	}
}

package main

import (
	"bufio"
	"fmt"
	"os"
)

var s [51][51]byte

func main() {
	var n, m, x0, x1, y0, y1 int
	x0, y0, x1, y1 = 51, 51, -1, -1
	in := bufio.NewScanner(os.Stdin)
	in.Split(bufio.ScanWords)
	fmt.Scan(&n, &m)
	for i := 0; i < n; i++ {
		in.Scan()
		for j := 0; j < m; j++ {
			s[i][j] = in.Text()[j]
			if s[i][j] == '*' {
				if i < x0 {
					x0 = i
				}
				if j < y0 {
					y0 = j
				}
				if i > x1 {
					x1 = i
				}
				if j > y1 {
					y1 = j
				}
			}
		}
	}
	for i := x0; i <= x1; i++ {
		for j := y0; j <= y1; j++ {
			fmt.Print(string(s[i][j]))
		}
		fmt.Println()
	}
}

// 14A
package main

import (
	"bufio"
	"fmt"
	"os"
)

func main() {
	var ch [50][50]byte
	var n, m int
	x1, y1, x2, y2 := 51, 51, -1, -1
	in := bufio.NewScanner(os.Stdin)
	in.Split(bufio.ScanWords)
	fmt.Scan(&n, &m)
	for i := 0; i < n; i++ {
		in.Scan()
		for j := 0; j < m; j++ {
			ch[i][j] = in.Text()[j]
			//fmt.Scan(&ch[i][j])
			if ch[i][j] == '*' {
				if i < x1 {
					x1 = i
				}
				if i > x2 {
					x2 = i
				}
				if j < y1 {
					y1 = j
				}
				if j > y2 {
					y2 = j
				}
			}
		}
	}
	for i := x1; i <= x2; i++ {
		for j := y1; j <= y2; j++ {
			fmt.Print(string(ch[i][j]))
		}
		fmt.Println()
	}
}

// 14A
package main

import (
	"bufio"
	"fmt"
	"os"
)

func main() {
	var n, m int
	in := bufio.NewScanner(os.Stdin)
	in.Split(bufio.ScanWords)
	fmt.Scan(&n, &m)
	ch := make([]string, n)
	x1, y1, x2, y2 := 51, 51, -1, -1
	for i := 0; i < n; i++ {
		in.Scan()
		ch[i] = in.Text()
		//fmt.Scan(&ch[i])
		for j := 0; j < m; j++ {
			if ch[i][j] == '*' {
				if i < x1 {
					x1 = i
				}
				if i > x2 {
					x2 = i
				}
				if j < y1 {
					y1 = j
				}
				if j > y2 {
					y2 = j
				}
			}
		}
	}
	for i := x1; i <= x2; i++ {
		for j := y1; j <= y2; j++ {
			fmt.Print(string(ch[i][j]))
		}
		fmt.Println()
	}
}

// 14A-mic
package main

import (
    "fmt"
    "math"
)

func main() {
    var n, m int
    min_i := 1000
    min_j := 1000
    max_i := 0
    max_j := 0
    fmt.Scan(&n, &m)
    a := make([]string, n)
    for j := 0; j < n; j++ {
        fmt.Scan(&a[j])
        for i := 0; i < m; i++ {
            if a[j][i] == '*' {
                min_j = int(math.Min(float64(min_j), float64(j)))
                min_i = int(math.Min(float64(min_i), float64(i)))
                max_j = int(math.Max(float64(max_j), float64(j)))
                max_i = int(math.Max(float64(max_i), float64(i)))
            }
        }
    }
    for i := min_j; i <= max_j; i++ {
        for j := min_i; j <= max_i; j++ {
            fmt.Print(string(a[i][j]))
        }
        fmt.Println()
    }
}

package main

import "os"
import "bufio"
import "strconv"

func main(){
	var n, m int
	r := bufio.NewScanner(os.Stdin)
	r.Split(bufio.ScanWords)
	w := bufio.NewWriter(os.Stdout)
	r.Scan()
	n, _ = strconv.Atoi(r.Text())
	r.Scan()
	m, _ = strconv.Atoi(r.Text())
	letter := make([]string, n)
	for i:=0; i<n; i++ {
		r.Scan()
		letter[i] = r.Text()
	}
	lmin := -1
	imin := 0
	lmax := 0
	imax := 0
	for j:=0; j<n; j++ {
		for k:=0; k<m; k++ {
			if string(letter[j][k]) == "*" {
				lmin = j
				imin = k
				break
			}
		}
		if lmin != -1 {
			break
		}
	}
	for j:=lmin; j<n; j++ {
		for k:=0; k<m; k++ {
			if string(letter[j][k]) == "*" {
				if k < imin {
					imin = k
				}
				if j > lmax {
					lmax = j
				}
				if k > imax {
					imax = k
				}
			}
		}
	}
	for l:=lmin; l<=lmax; l++ {
		for x:=imin; x<=imax; x++ {
			w.WriteString(string(letter[l][x]))
		}
		w.WriteString("\n")
	}
	w.Flush()
}

package main

import (
	"bufio"
	"fmt"
	"os"
)

func main() {

	//
	scn := bufio.NewScanner(os.Stdin)
	for {
		fmt.Println("Enter Lines:")
		var lines []string
		for scn.Scan() {
			line := scn.Text()
			if len(line) == 1 {
				// Group Separator (GS ^]): ctrl-]
				if line[0] == '\x1D' {
					break
				}
			}
			lines = append(lines, line)
		}

		if len(lines) > 0 {
			fmt.Println()
			fmt.Println("Result:")
			for _, line := range lines {
				fmt.Println(line)
			}
			fmt.Println()
		}

		if err := scn.Err(); err != nil {
			fmt.Fprintln(os.Stderr, err)
			break
		}
		if len(lines) == 0 {
			break
		}
	}
}

package main

import "fmt"

func main() {
	var x,z int
	var s [55]string
	fmt.Scan(&x,&z)
	minR, maxR, minC, maxC := z-1, 0, z-1, 0
	for i := 0; i < x; i++ {
		fmt.Scan(&s[i])
		for j := 0; j < z; j++ {
			if s[i][j] == '*' {
				if minR > i { minR = i }
				if maxR < i { maxR = i }
				if minC > j { minC = j }
				if maxC < j { maxC = j }
			}
		}
	}
	for i := 0; i < x; i++ {
		if (i >= minR) && (i <= maxR) {
			for j := 0; j < z; j++ {
				if (j >= minC) && (j <= maxC) { fmt.Print(string(s[i][j])) }
			}
			fmt.Println()
		}
	}
}

package main

import (
	"bufio"
	"fmt"
	"os"
)

var s [51][51]byte

func main() {
	var n, m, x0, x1, y0, y1, flag0, flag1 int
	in := bufio.NewScanner(os.Stdin)
	in.Split(bufio.ScanWords)
	fmt.Scan(&n, &m)
	for i := 0; i < n; i++ {
		in.Scan()
		for j := 0; j < m; j++ {
			s[i][j] = in.Text()[j]
			if s[i][j] == '*' {
				if flag0 == 0 {
					x0 = i
					flag0 = 1
				}
				if flag1 == 0 {
					y0 = j
					flag1 = 1
				}
				x1 = i
				y1 = j
			}
		}
	}
	for i := x0; i <= x1; i++ {
		for j := y0; j <= y1; j++ {
			fmt.Print(string(s[i][j]))
		}
		fmt.Println()
	}
}

package main

import "fmt"

func main() {
    var n,m int
    var s [55]string
    var row [55]bool
    fmt.Scan(&n,&m)
    mincol, maxcol := m-1, 0
    for i := 0; i < n; i++ {
        fmt.Scan(&s[i])
        for j := 0; j < m; j++ {
            if s[i][j] == '*' {
                row[i] = true
                if mincol > j { mincol = j }
                if maxcol < j { maxcol = j }
            }
        }
    }
    for i := 0; i < n; i++ {
        if row[i] {
            for j := 0; j < m; j++ {
                if (j >= mincol) && (j <= maxcol) { fmt.Print(string(s[i][j])) }
            }
            fmt.Println()
        }
    }
}

// 14A
package main

import (
	"bufio"
	"fmt"
	"os"
)

func main() {
	var ch [50][50]byte
	var n, m int
	x1, y1, x2, y2 := 51, 51, -1, -1
	in := bufio.NewScanner(os.Stdin)
	in.Split(bufio.ScanWords)
	fmt.Scan(&n, &m)
	for i := 0; i < n; i++ {
		in.Scan()
		for j := 0; j < m; j++ {
			ch[i][j] = in.Text()[j]
			//fmt.Scan(&ch[i][j])
			if ch[i][j] == '*' {
				if i < x1 {
					x1 = i
				}
				if i > x2 {
					x2 = i
				}
				if j < y1 {
					y1 = j
				}
				if j > y2 {
					y2 = j
				}
			}
		}
	}
	for i := x1; i <= x2; i++ {
		for j := y1; j <= y2; j++ {
			fmt.Print(string(ch[i][j]))
		}
	}
}

// 14A-mic
package main

import (
    "fmt"
    "math"
)

func main() {
    var n, m int
    min_i := 1000
    min_j := 1000
    max_i := 0
    max_j := 0
    fmt.Scan(&n, &m)
    a := make([]string, m)
    for j := 0; j < m; j++ {
        fmt.Scan(&a[j])
        for i := 0; i < len(a[j]); i++ {
            if a[j][i] == '*' {
                min_j = int(math.Min(float64(min_j), float64(j)))
                min_i = int(math.Min(float64(min_i), float64(i)))
                max_j = int(math.Max(float64(max_j), float64(j)))
                max_i = int(math.Max(float64(max_i), float64(i)))
            }
        }
    }
    for i := min_j; i <= max_j; i++ {
        for j := min_i; j <= max_i; j++ {
            fmt.Print(string(a[i][j]))
        }
        fmt.Println()
    }
}

// 14A-mic
package main

import (
    "fmt"
    "math"
)

func main() {
    var n, m int
    min_i := 1000
    min_j := 1000
    max_i := -1
    max_j := -1
    fmt.Scan(&n, &m)
    a := make([]string, m)
    for j := 0; j < m; j++ {
        fmt.Scan(&a[j])
        for i := 0; i < len(a[j]); i++ {
            if a[j][i] == '*' {
                min_j = int(math.Min(float64(min_i), float64(i)))
                min_i = int(math.Min(float64(min_j), float64(j)))
                max_j = int(math.Max(float64(max_i), float64(i)))
                max_i = int(math.Max(float64(max_j), float64(j)))
            }
        }
    }
    for i := min_j; i <= max_j; i++ {
        for j := min_i; j <= max_i; j++ {
            fmt.Print(string(a[i][j]))
        }
        fmt.Println()
    }
}