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

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

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

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

j = A("j")
m = B("m")
h = C("h")
i = D("i")
b = D("b")
d = C("d")

j.u = b
m.t = h
m.v = j
h.s = j
h.x = i
h.r = d
i.z = m
b.z = m
d.s = j
d.x = b
d.r = h
assert j.u.z.v.txt == "
class A:
    def __init__(self, txt: str):
        self.u: D = None
        self.txt = txt

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

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

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

j = A("j")
m = B("m")
h = C("h")
i = D("i")
b = D("b")
d = C("d")

j.u = b
m.t = h
m.v = j
h.s = j
h.x = i
h.r = d
i.z = m
b.z = m
d.s = j
d.x = b
d.r = h
assert j.u.z.v.txt == "j"