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

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

m = A("m")
i = B("i")
g = A("g")

m.u = g
i.t = g
g.u = m
assert g.u.u.u.txt == "
class A:
    def __init__(self, txt: str):
        self.u: A = None
        self.txt = txt

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

m = A("m")
i = B("i")
g = A("g")

m.u = g
i.t = g
g.u = m
assert g.u.u.u.txt == "m"