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

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

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

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

m.t = g
j.z = i
j.t = i
j.r = m
i.z = j
i.y = j
i.x = m
g.z = j
g.y = j
g.x = m
assert m.t.x.t.x.txt == "
class A:
    def __init__(self, txt: str):
        self.t: C = None
        self.txt = txt

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

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

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

m.t = g
j.z = i
j.t = i
j.r = m
i.z = j
i.y = j
i.x = m
g.z = j
g.y = j
g.x = m
assert m.t.x.t.x.txt == "m"