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

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

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

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

d = A("d")
n = B("n")
j = C("j")
k = D("k")

d.w = k
n.o = d
n.t = j
n.v = j
j.u = d
j.v = d
j.w = n
k.r = d
assert k.r.w.r.txt == "
class A:
    def __init__(self, txt: str):
        self.w: D = None
        self.txt = txt

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

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

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

d = A("d")
n = B("n")
j = C("j")
k = D("k")

d.w = k
n.o = d
n.t = j
n.v = j
j.u = d
j.v = d
j.w = n
k.r = d
assert k.r.w.r.txt == "d"