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

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

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

b = A("b")
d = B("d")
n = C("n")

b.z = d
b.r = n
b.w = n
d.x = n
d.r = n
n.t = b
assert n.t.w.t.txt == "
class A:
    def __init__(self, txt: str):
        self.z: B = None
        self.r: C = None
        self.w: C = None
        self.txt = txt

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

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

b = A("b")
d = B("d")
n = C("n")

b.z = d
b.r = n
b.w = n
d.x = n
d.r = n
n.t = b
assert n.t.w.t.txt == "b"