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

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

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

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

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

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

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