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

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

n = A("n")
f = B("f")
i = B("i")
l = B("l")
d = A("d")
a = A("a")

n.x = l
n.p = i
f.x = a
i.x = n
l.x = d
d.x = l
d.p = l
a.x = f
a.p = l
assert l.x.p.x.x.txt == "
class A:
    def __init__(self, txt: str):
        self.x: B = None
        self.p: B = None
        self.txt = txt

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

n = A("n")
f = B("f")
i = B("i")
l = B("l")
d = A("d")
a = A("a")

n.x = l
n.p = i
f.x = a
i.x = n
l.x = d
d.x = l
d.p = l
a.x = f
a.p = l
assert l.x.p.x.x.txt == "l"