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

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

f = A("f")
k = B("k")
m = A("m")
n = B("n")
c = A("c")

f.w = c
f.p = c
k.t = f
m.w = f
m.p = f
n.t = c
c.w = f
c.p = f
assert m.p.p.p.w.w.txt == "
class A:
    def __init__(self, txt: str):
        self.w: A = None
        self.p: A = None
        self.txt = txt

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

f = A("f")
k = B("k")
m = A("m")
n = B("n")
c = A("c")

f.w = c
f.p = c
k.t = f
m.w = f
m.p = f
n.t = c
c.w = f
c.p = f
assert m.p.p.p.w.w.txt == "f"