i have a database of transactions between customers that can be described as in:

```
Transaction ID  Sender  Receiver    Sender  Receiver Receipt
1   A   B   2   4
2   C   A   5   1
3   B   C   5   1
4   C   B   3   4

```

database is sorted ascending by transaction id; how is it possible to get the last receipt number (sender or receiver) for each customer

for example
A:1 (the last occurrence of A is in row 2 as a sender)
B:4 (the last occurrence of B is in row 4 as a Receiver)
C:3 (the last occurrence of C is in row 4 as a sender)

Thank You,