def derive_utxo(blockchain):
    utxo = {}

    for block in blockchain:
        for tx in block:
            for inp in tx['inputs']:
                utxo.pop(inp, None)

            utxo.update({
                (tx['tx_id'], i): v
                for i, v in tx['outputs']
            })

    return utxo


blockchain = [
    [
        {
            'tx_id': 'tx1',
            'inputs': [],
            'outputs': [(0, 10), (1, 5)]
        },
        {
            'tx_id': 'tx2',
            'inputs': [('tx1', 0)],
            'outputs': [(2, 8)]
        }
    ],

    [
        {
            'tx_id': 'tx3',
            'inputs': [('tx1', 1)],
            'outputs': [(3, 4)]
        },
        {
            'tx_id': 'tx4',
            'inputs': [('tx2', 0)],
            'outputs': [(4, 7), (5, 3)]
        }
    ]
]


for (tx_id, idx), value in derive_utxo(blockchain).items():
    print(f"TX: {tx_id}, Output: {idx}, Value: {value}")