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

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

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

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

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

j.x = h
j.u = m
h.x = k
h.u = k
m.q = j
m.o = h
m.u = k
k.p = j
assert j.u.q.x.u.txt == "
class A:
    def __init__(self, txt: str):
        self.x: B = None
        self.u: C = None
        self.txt = txt

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

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

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

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

j.x = h
j.u = m
h.x = k
h.u = k
m.q = j
m.o = h
m.u = k
k.p = j
assert j.u.q.x.u.txt == "k"