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

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

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

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

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

a.u = k
k.x = n
k.p = n
n.q = k
m.y = n
m.s = n
assert n.q.x.q.txt == "
class A:
    def __init__(self, txt: str):
        self.u: B = None
        self.txt = txt

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

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

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

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

a.u = k
k.x = n
k.p = n
n.q = k
m.y = n
m.s = n
assert n.q.x.q.txt == "k"