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

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

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

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

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

k.q = m
m.v = d
m.o = k
m.x = k
m.u = h
h.t = m
d.s = k
d.t = k
d.y = h
d.p = h
assert k.q.x.q.txt == "
class A:
    def __init__(self, txt: str):
        self.q: B = None
        self.txt = txt

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

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

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

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

k.q = m
m.v = d
m.o = k
m.x = k
m.u = h
h.t = m
d.s = k
d.t = k
d.y = h
d.p = h
assert k.q.x.q.txt == "m"