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

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

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

e = A("e")
m = B("m")
j = C("j")
i = A("i")
d = B("d")
g = A("g")

e.p = g
m.z = d
j.r = m
j.o = d
i.p = e
d.z = m
g.p = i
assert e.p.p.p.p.p.p.txt == "
class A:
    def __init__(self, txt: str):
        self.p: A = None
        self.txt = txt

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

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

e = A("e")
m = B("m")
j = C("j")
i = A("i")
d = B("d")
g = A("g")

e.p = g
m.z = d
j.r = m
j.o = d
i.p = e
d.z = m
g.p = i
assert e.p.p.p.p.p.p.txt == "e"