#!/bin/bash

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

cnt=0;
for i in {a..c}; do
  a[${i}]=$(echo ${a[${i}]} | sed "s/\n//")
done


turn=a


while [ -n "${a[${turn}]}" ] ;do
  next=${a[${turn}]:0:1}
  a[${turn}]=${a[${turn}]:1}
  turn=$next
done

echo ${turn^^}
