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

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

c = A("c")
g = B("g")
n = A("n")
d = B("d")

c.q = n
g.u = c
g.x = d
n.q = c
d.u = n
d.x = g
assert g.x.u.q.txt == "
class A:
    def __init__(self, txt: str):
        self.q: A = None
        self.txt = txt

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

c = A("c")
g = B("g")
n = A("n")
d = B("d")

c.q = n
g.u = c
g.x = d
n.q = c
d.u = n
d.x = g
assert g.x.u.q.txt == "c"