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

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

f = A("f")
l = B("l")
j = B("j")
h = A("h")
a = A("a")
m = B("m")
n = B("n")
i = B("i")

f.p = a
l.w = f
j.w = f
h.p = f
a.p = f
m.w = h
n.w = f
i.w = h
assert j.w.p.p.p.p.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.w: A = None
        self.txt = txt

f = A("f")
l = B("l")
j = B("j")
h = A("h")
a = A("a")
m = B("m")
n = B("n")
i = B("i")

f.p = a
l.w = f
j.w = f
h.p = f
a.p = f
m.w = h
n.w = f
i.w = h
assert j.w.p.p.p.p.p.p.txt == "f"