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

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

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

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

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

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

i.q = n
i.r = n
c.u = i
c.r = g
n.u = i
n.r = c
g.u = i
g.r = n
assert g.u.r.u.q.txt == "n"