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

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

l = A("l")
f = B("f")
b = A("b")
c = A("c")
k = A("k")
d = A("d")
e = B("e")
i = A("i")

l.x = e
f.p = i
b.x = f
c.x = f
k.x = f
d.x = e
e.p = i
i.x = f
assert k.x.p.x.txt == "
class A:
    def __init__(self, txt: str):
        self.x: B = None
        self.txt = txt

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

l = A("l")
f = B("f")
b = A("b")
c = A("c")
k = A("k")
d = A("d")
e = B("e")
i = A("i")

l.x = e
f.p = i
b.x = f
c.x = f
k.x = f
d.x = e
e.p = i
i.x = f
assert k.x.p.x.txt == "f"