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

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

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

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

m = A("m")
j = B("j")
c = C("c")
b = D("b")

m.u = b
m.r = j
m.t = c
j.x = m
j.q = c
c.o = j
b.r = j
b.w = c
assert b.w.o.x.txt == "
class A:
    def __init__(self, txt: str):
        self.u: D = None
        self.r: B = None
        self.t: C = None
        self.txt = txt

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

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

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

m = A("m")
j = B("j")
c = C("c")
b = D("b")

m.u = b
m.r = j
m.t = c
j.x = m
j.q = c
c.o = j
b.r = j
b.w = c
assert b.w.o.x.txt == "m"