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

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

a = A("a")
g = B("g")
c = B("c")
l = B("l")

a.y = c
g.v = a
g.s = a
c.v = a
c.s = a
l.v = a
l.s = a
assert l.v.y.v.txt == "
class A:
    def __init__(self, txt: str):
        self.y: B = None
        self.txt = txt

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

a = A("a")
g = B("g")
c = B("c")
l = B("l")

a.y = c
g.v = a
g.s = a
c.v = a
c.s = a
l.v = a
l.s = a
assert l.v.y.v.txt == "a"