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

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

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

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

m = A("m")
k = B("k")
i = C("i")
j = D("j")
n = C("n")
a = B("a")

m.o = a
k.v = a
k.u = a
k.q = j
k.w = n
i.q = k
i.r = a
j.r = m
n.q = k
n.r = k
a.v = k
a.u = k
a.q = j
a.w = n
assert a.w.r.q.txt == "
class A:
    def __init__(self, txt: str):
        self.o: B = None
        self.txt = txt

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

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

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

m = A("m")
k = B("k")
i = C("i")
j = D("j")
n = C("n")
a = B("a")

m.o = a
k.v = a
k.u = a
k.q = j
k.w = n
i.q = k
i.r = a
j.r = m
n.q = k
n.r = k
a.v = k
a.u = k
a.q = j
a.w = n
assert a.w.r.q.txt == "j"