#!/bin/bash

declare -A a
read a["a"]
read a["b"]
read a["c"]

turn=a


while [ -n "${a[${turn}]}" ] ;do
  next=$(echo ${a[${turn}]} | grep -o "^.")
  a[${turn}]=$(echo ${a[${turn}]} | sed "s/^.//")
  turn=$next
done

echo ${turn^^}
