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

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

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

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

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

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

g.x = m
g.u = m
m.r = g
a.r = g
assert a.r.x.r.txt == "g"