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

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

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

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

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

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

i.r = e
i.x = k
m.q = k
m.v = g
e.q = k
e.v = i
g.r = k
g.x = k
k.q = m
k.v = g
assert k.v.r.v.txt == "g"