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

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

i = A("i")
k = B("k")
g = A("g")

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

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

i = A("i")
k = B("k")
g = A("g")

i.r = g
i.q = k
k.u = i
g.r = i
g.q = k
assert g.q.u.q.txt == "k"