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

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

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

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

n = A("n")
b = B("b")
k = C("k")
a = D("a")

n.q = b
b.u = n
k.o = b
k.y = a
k.z = a
a.u = k
assert n.q.u.q.txt == "
class A:
    def __init__(self, txt: str):
        self.q: B = None
        self.txt = txt

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

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

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

n = A("n")
b = B("b")
k = C("k")
a = D("a")

n.q = b
b.u = n
k.o = b
k.y = a
k.z = a
a.u = k
assert n.q.u.q.txt == "b"