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

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

g = A("g")
i = B("i")
n = A("n")
b = B("b")

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

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

g = A("g")
i = B("i")
n = A("n")
b = B("b")

g.u = n
g.q = b
i.u = g
n.u = g
n.q = b
b.u = n
assert b.u.q.u.u.txt == "g"