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

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

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

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

j = A("j")
m = B("m")
n = C("n")
e = D("e")
l = D("l")

j.t = m
j.q = n
m.r = n
m.w = j
n.z = m
e.w = n
e.o = j
e.v = m
l.w = n
l.o = j
l.v = m
assert m.r.z.w.txt == "
class A:
    def __init__(self, txt: str):
        self.t: B = None
        self.q: C = None
        self.txt = txt

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

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

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

j = A("j")
m = B("m")
n = C("n")
e = D("e")
l = D("l")

j.t = m
j.q = n
m.r = n
m.w = j
n.z = m
e.w = n
e.o = j
e.v = m
l.w = n
l.o = j
l.v = m
assert m.r.z.w.txt == "j"