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

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

m = A("m")
k = B("k")
d = B("d")
n = A("n")
a = A("a")
c = B("c")

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

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

m = A("m")
k = B("k")
d = B("d")
n = A("n")
a = A("a")
c = B("c")

m.s = a
m.u = d
k.y = a
d.y = m
n.s = a
n.u = c
a.s = m
a.u = k
c.y = n
assert d.y.u.y.u.y.s.txt == "a"