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

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

e = A("e")
f = B("f")
n = A("n")

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

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

e = A("e")
f = B("f")
n = A("n")

e.q = f
f.v = n
n.q = f
assert f.v.q.v.txt == "n"