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

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

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

k = A("k")
c = B("c")
a = C("a")
e = B("e")

k.z = c
c.x = a
c.r = e
a.x = k
e.x = a
e.r = c
assert c.x.x.z.txt == "
class A:
    def __init__(self, txt: str):
        self.z: B = None
        self.txt = txt

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

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

k = A("k")
c = B("c")
a = C("a")
e = B("e")

k.z = c
c.x = a
c.r = e
a.x = k
e.x = a
e.r = c
assert c.x.x.z.txt == "c"