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

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

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

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

j = A("j")
i = B("i")
f = C("f")
b = D("b")
a = C("a")
n = B("n")

j.z = b
i.u = n
i.r = n
f.r = i
b.w = j
b.s = j
b.y = a
b.q = a
a.r = n
n.u = i
n.r = i
assert f.r.u.u.r.txt == "
class A:
    def __init__(self, txt: str):
        self.z: D = None
        self.txt = txt

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

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

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

j = A("j")
i = B("i")
f = C("f")
b = D("b")
a = C("a")
n = B("n")

j.z = b
i.u = n
i.r = n
f.r = i
b.w = j
b.s = j
b.y = a
b.q = a
a.r = n
n.u = i
n.r = i
assert f.r.u.u.r.txt == "n"