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

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

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

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

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

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

f.r = c
f.v = g
m.v = k
c.v = f
g.v = f
k.r = m
k.v = c
assert c.v.r.v.txt == "f"