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

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

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

e = A("e")
c = B("c")
g = C("g")
m = C("m")

e.p = c
c.u = g
c.y = e
g.z = m
m.z = g
assert g.z.z.z.z.txt == "
class A:
    def __init__(self, txt: str):
        self.p: B = None
        self.txt = txt

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

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

e = A("e")
c = B("c")
g = C("g")
m = C("m")

e.p = c
c.u = g
c.y = e
g.z = m
m.z = g
assert g.z.z.z.z.txt == "g"