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

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

c = A("c")
a = B("a")
k = A("k")
m = B("m")
g = B("g")
f = A("f")

c.r = m
a.q = g
a.w = k
k.r = m
m.q = g
m.w = c
g.q = a
g.w = k
f.r = a
assert f.r.q.q.txt == "
class A:
    def __init__(self, txt: str):
        self.r: B = None
        self.txt = txt

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

c = A("c")
a = B("a")
k = A("k")
m = B("m")
g = B("g")
f = A("f")

c.r = m
a.q = g
a.w = k
k.r = m
m.q = g
m.w = c
g.q = a
g.w = k
f.r = a
assert f.r.q.q.txt == "a"