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

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

n = A("n")
k = B("k")
e = A("e")
d = B("d")

n.s = d
n.u = k
k.y = n
k.z = e
e.s = d
e.u = k
d.y = n
d.z = e
assert e.u.z.u.y.txt == "
class A:
    def __init__(self, txt: str):
        self.s: B = None
        self.u: B = None
        self.txt = txt

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

n = A("n")
k = B("k")
e = A("e")
d = B("d")

n.s = d
n.u = k
k.y = n
k.z = e
e.s = d
e.u = k
d.y = n
d.z = e
assert e.u.z.u.y.txt == "n"