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

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

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

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

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

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

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