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

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

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

e = A("e")
d = B("d")
c = C("c")
b = B("b")
n = B("n")
i = B("i")
f = B("f")
h = A("h")

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

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

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

e = A("e")
d = B("d")
c = C("c")
b = B("b")
n = B("n")
i = B("i")
f = B("f")
h = A("h")

e.o = h
d.p = c
c.p = b
b.p = c
n.p = c
i.p = c
f.p = c
h.o = e
assert h.o.o.o.o.o.o.txt == "h"