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

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

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

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

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

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

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