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

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

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

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

m = A("m")
n = B("n")
h = C("h")
f = D("f")
b = C("b")

m.y = n
n.s = h
n.t = m
h.x = n
h.y = f
f.z = b
f.w = n
f.q = m
b.x = n
b.y = f
assert m.y.t.y.txt == "
class A:
    def __init__(self, txt: str):
        self.y: B = None
        self.txt = txt

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

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

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

m = A("m")
n = B("n")
h = C("h")
f = D("f")
b = C("b")

m.y = n
n.s = h
n.t = m
h.x = n
h.y = f
f.z = b
f.w = n
f.q = m
b.x = n
b.y = f
assert m.y.t.y.txt == "n"