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

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

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

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

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

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

m.u = k
k.t = m
l.u = k
assert m.u.t.u.txt == "k"