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

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

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

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

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

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

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