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

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

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

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

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

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

l.x = m
l.t = k
m.t = l
m.s = l
k.x = m
k.t = l
assert m.t.x.s.txt == "l"