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

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

d = A("d")
m = B("m")
k = A("k")
l = B("l")
b = B("b")

d.p = k
d.w = b
m.y = b
m.u = d
k.p = d
k.w = b
l.y = m
l.u = k
b.y = l
b.u = d
assert l.u.p.w.txt == "
class A:
    def __init__(self, txt: str):
        self.p: A = None
        self.w: B = None
        self.txt = txt

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

d = A("d")
m = B("m")
k = A("k")
l = B("l")
b = B("b")

d.p = k
d.w = b
m.y = b
m.u = d
k.p = d
k.w = b
l.y = m
l.u = k
b.y = l
b.u = d
assert l.u.p.w.txt == "b"