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

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

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

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

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

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

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