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

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

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

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

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

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

n.x = m
g.t = n
g.r = n
m.x = n
assert g.t.x.x.txt == "n"