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

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

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

l = A("l")
d = B("d")
b = C("b")
h = A("h")

l.t = h
l.p = b
l.z = b
d.x = h
d.y = h
b.w = d
b.s = d
h.t = l
h.p = b
h.z = b
assert d.y.t.t.txt == "
class A:
    def __init__(self, txt: str):
        self.t: A = None
        self.p: C = None
        self.z: C = None
        self.txt = txt

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

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

l = A("l")
d = B("d")
b = C("b")
h = A("h")

l.t = h
l.p = b
l.z = b
d.x = h
d.y = h
b.w = d
b.s = d
h.t = l
h.p = b
h.z = b
assert d.y.t.t.txt == "h"