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

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

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

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

k = A("k")
h = B("h")
m = C("m")
b = D("b")
c = D("c")

k.u = c
h.q = c
h.s = m
m.w = h
m.r = h
m.q = k
b.s = c
b.o = k
b.y = h
c.s = b
c.o = k
c.y = h
assert m.q.u.s.txt == "
class A:
    def __init__(self, txt: str):
        self.u: D = None
        self.txt = txt

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

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

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

k = A("k")
h = B("h")
m = C("m")
b = D("b")
c = D("c")

k.u = c
h.q = c
h.s = m
m.w = h
m.r = h
m.q = k
b.s = c
b.o = k
b.y = h
c.s = b
c.o = k
c.y = h
assert m.q.u.s.txt == "b"