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

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

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

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

a = A("a")
i = B("i")
d = C("d")
b = D("b")

a.u = b
a.w = i
a.r = d
i.r = a
d.t = b
d.o = i
b.w = i
b.y = d
assert i.r.u.w.r.txt == "
class A:
    def __init__(self, txt: str):
        self.u: D = None
        self.w: B = None
        self.r: C = None
        self.txt = txt

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

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

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

a = A("a")
i = B("i")
d = C("d")
b = D("b")

a.u = b
a.w = i
a.r = d
i.r = a
d.t = b
d.o = i
b.w = i
b.y = d
assert i.r.u.w.r.txt == "a"