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

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

k = A("k")
i = B("i")
a = A("a")
b = A("b")
c = B("c")
f = B("f")
m = A("m")

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

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

k = A("k")
i = B("i")
a = A("a")
b = A("b")
c = B("c")
f = B("f")
m = A("m")

k.w = m
k.q = i
i.p = f
a.w = m
a.q = i
b.w = a
b.q = f
c.p = i
f.p = i
m.w = a
m.q = f
assert m.q.p.p.p.p.txt == "f"