import math


def range_min_query(tree, query_low, query_high, low, high, pos):
    """
    Query range on list input using its segment tree.

    tree: segment tree of list input
    low: range begin of input list
    high: range end of input list
    query_low: query range begin in input list
    query_high: query range end in input list
    pos: current pointer location
    """
    # total overlap case
    if query_low <= low and query_high >= high:
        return tree[pos]

    # no overlap
    if query_low > high or query_high < low:
        return math.inf

    # partial overlap
    mid = (low + high) // 2
    arg1 = range_min_query(tree, query_low, query_high,
                           low=low,
                           high=mid,
                           pos=2 * pos + 1)
    arg2 = range_min_query(tree, query_low, query_high,
                           low=mid + 1,
                           high=high,
                           pos=2 * pos + 2)
    # print(f"compare {arg1} and {arg2}")
    return min(arg1, arg2)