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

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

b = A("b")
k = B("k")
i = A("i")
e = A("e")
m = B("m")
c = B("c")

b.p = e
b.w = i
k.q = b
k.x = i
i.p = b
i.w = e
e.p = b
e.w = b
m.q = b
m.x = b
c.q = b
c.x = b
assert k.x.w.p.txt == "
class A:
    def __init__(self, txt: str):
        self.p: A = None
        self.w: A = None
        self.txt = txt

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

b = A("b")
k = B("k")
i = A("i")
e = A("e")
m = B("m")
c = B("c")

b.p = e
b.w = i
k.q = b
k.x = i
i.p = b
i.w = e
e.p = b
e.w = b
m.q = b
m.x = b
c.q = b
c.x = b
assert k.x.w.p.txt == "b"