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

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

l = A("l")
b = B("b")
f = B("f")
n = A("n")
g = A("g")
c = B("c")

l.p = n
b.p = f
b.s = n
f.p = b
f.s = l
n.p = l
g.p = l
c.p = f
c.s = g
assert l.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.p: B = None
        self.s: A = None
        self.txt = txt

l = A("l")
b = B("b")
f = B("f")
n = A("n")
g = A("g")
c = B("c")

l.p = n
b.p = f
b.s = n
f.p = b
f.s = l
n.p = l
g.p = l
c.p = f
c.s = g
assert l.p.p.p.p.p.txt == "n"