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

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

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

i = A("i")
a = B("a")
m = C("m")
h = B("h")
e = B("e")

i.x = a
a.y = m
a.r = m
a.o = e
m.p = h
h.y = m
h.r = m
h.o = a
e.y = m
e.r = m
e.o = h
assert e.o.r.p.o.txt == "
class A:
    def __init__(self, txt: str):
        self.x: B = None
        self.txt = txt

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

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

i = A("i")
a = B("a")
m = C("m")
h = B("h")
e = B("e")

i.x = a
a.y = m
a.r = m
a.o = e
m.p = h
h.y = m
h.r = m
h.o = a
e.y = m
e.r = m
e.o = h
assert e.o.r.p.o.txt == "a"