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

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

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

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

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

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

f.y = l
f.v = k
g.x = k
g.r = k
a.y = f
a.v = g
l.y = f
l.v = g
k.x = g
k.r = g
assert a.v.r.r.txt == "g"