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

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

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

l.x = k
k.o = m
m.x = k
assert m.x.o.x.txt == "
class A:
    def __init__(self, txt: str):
        self.x: B = None
        self.txt = txt

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

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

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