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

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

b = A("b")
j = B("j")
g = B("g")

b.q = g
j.u = b
j.x = g
g.u = b
g.x = j
assert b.q.x.x.txt == "
class A:
    def __init__(self, txt: str):
        self.q: B = None
        self.txt = txt

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

b = A("b")
j = B("j")
g = B("g")

b.q = g
j.u = b
j.x = g
g.u = b
g.x = j
assert b.q.x.x.txt == "g"