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

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

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

m.y = g
g.t = m
h.t = m
assert h.t.y.t.txt == "
class A:
    def __init__(self, txt: str):
        self.y: B = None
        self.txt = txt

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

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

m.y = g
g.t = m
h.t = m
assert h.t.y.t.txt == "m"