def merge(a: dict, b: dict) ->dict:
    """Deep merge of 2 dict objects.

    Take the values in dict "b" and merge them
    into dict "a". If a key exists in both inputs
    the value from "b" will be used.
    """
    queue = list()
    ret = dict()
    queue.append((ret, a, b))
    while len(queue) > 0:
        root, left, right = queue.pop()
        for rk, rv in right.items():
            if rk not in left:
                root[rk] = rv
            elif isinstance(rv, list) and isinstance(left[rk], list):
                root[rk] = left[rk] + rv
            elif isinstance(rv, dict) and isinstance(left[rk], dict):
                root[rk] = {}
                queue.append((root[rk], left[rk], rv))
            else:
                root[rk] = rv
        for lk, lv in left.items():
            if lk not in right:
                root[lk] = lv
    return ret
