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.o: A = None
        self.txt = txt

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

f.x = k
f.p = k
k.o = l
l.x = m
l.p = m
m.o = f
assert l.p.o.p.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.o: A = None
        self.txt = txt

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

f.x = k
f.p = k
k.o = l
l.x = m
l.p = m
m.o = f
assert l.p.o.p.txt == "k"