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

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

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

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

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

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

f.q = e
f.r = g
e.v = g
g.q = e
g.r = f
assert f.r.r.q.txt == "e"