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

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

k = A("k")
b = B("b")
m = B("m")
j = A("j")

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

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

k = A("k")
b = B("b")
m = B("m")
j = A("j")

k.p = j
b.u = m
b.p = m
m.u = b
m.p = b
j.p = k
assert b.u.p.p.txt == "m"