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

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

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

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

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

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

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