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

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

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

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

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

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

a.z = f
a.v = g
g.r = a
g.s = f
f.r = a
f.s = g
assert f.r.z.r.txt == "a"