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

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

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

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

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

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

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

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

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

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

h.q = n
k.v = h
k.o = n
k.u = n
m.o = h
m.w = n
n.u = h
j.o = h
j.w = n
assert m.o.q.u.txt == "h"