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

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

i = A("i")
c = B("c")
m = B("m")
f = A("f")

i.q = m
c.v = m
c.w = i
m.v = c
m.w = i
f.q = m
assert f.q.v.w.q.txt == "
class A:
    def __init__(self, txt: str):
        self.q: B = None
        self.txt = txt

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

i = A("i")
c = B("c")
m = B("m")
f = A("f")

i.q = m
c.v = m
c.w = i
m.v = c
m.w = i
f.q = m
assert f.q.v.w.q.txt == "m"