class A:
    def __init__(self, txt: str):
        self.s: A = None
        self.txt = txt

class B:
    def __init__(self, txt: str):
        self.y: C = None
        self.q: B = None
        self.txt = txt

class C:
    def __init__(self, txt: str):
        self.o: A = None
        self.txt = txt

h = A("h")
g = B("g")
f = C("f")
e = A("e")
k = B("k")
n = A("n")
c = B("c")
b = B("b")

h.s = n
g.y = f
g.q = c
f.o = n
e.s = n
k.y = f
k.q = g
n.s = h
c.y = f
c.q = b
b.y = f
b.q = k
assert e.s.s.s.s.s.s.txt == "
class A:
    def __init__(self, txt: str):
        self.s: A = None
        self.txt = txt

class B:
    def __init__(self, txt: str):
        self.y: C = None
        self.q: B = None
        self.txt = txt

class C:
    def __init__(self, txt: str):
        self.o: A = None
        self.txt = txt

h = A("h")
g = B("g")
f = C("f")
e = A("e")
k = B("k")
n = A("n")
c = B("c")
b = B("b")

h.s = n
g.y = f
g.q = c
f.o = n
e.s = n
k.y = f
k.q = g
n.s = h
c.y = f
c.q = b
b.y = f
b.q = k
assert e.s.s.s.s.s.s.txt == "h"