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

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

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

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

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

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

k.q = m
f.w = k
f.v = m
m.w = k
m.v = f
a.w = k
a.v = f
assert f.w.q.w.txt == "k"