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

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

m = A("m")
k = B("k")
j = A("j")
e = B("e")
d = A("d")
a = B("a")

m.u = j
m.s = d
k.u = m
k.p = e
j.u = m
j.s = m
e.u = j
e.p = k
d.u = j
d.s = m
a.u = d
a.p = k
assert m.u.u.s.u.txt == "
class A:
    def __init__(self, txt: str):
        self.u: A = None
        self.s: A = None
        self.txt = txt

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

m = A("m")
k = B("k")
j = A("j")
e = B("e")
d = A("d")
a = B("a")

m.u = j
m.s = d
k.u = m
k.p = e
j.u = m
j.s = m
e.u = j
e.p = k
d.u = j
d.s = m
a.u = d
a.p = k
assert m.u.u.s.u.txt == "j"