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

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

l = A("l")
f = B("f")
m = A("m")
k = B("k")
i = B("i")

l.p = m
f.w = k
m.p = l
k.w = i
i.w = k
assert l.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: B = None
        self.txt = txt

l = A("l")
f = B("f")
m = A("m")
k = B("k")
i = B("i")

l.p = m
f.w = k
m.p = l
k.w = i
i.w = k
assert l.p.p.p.p.txt == "l"