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

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

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

i = A("i")
n = B("n")
f = C("f")
h = B("h")
a = C("a")
e = C("e")
g = A("g")
b = C("b")

i.s = g
n.t = a
n.o = g
f.p = a
h.t = f
h.o = g
a.p = b
e.p = b
g.s = i
b.p = a
assert a.p.p.p.p.p.txt == "
class A:
    def __init__(self, txt: str):
        self.s: A = None
        self.txt = txt

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

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

i = A("i")
n = B("n")
f = C("f")
h = B("h")
a = C("a")
e = C("e")
g = A("g")
b = C("b")

i.s = g
n.t = a
n.o = g
f.p = a
h.t = f
h.o = g
a.p = b
e.p = b
g.s = i
b.p = a
assert a.p.p.p.p.p.txt == "b"