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

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

b = A("b")
g = B("g")
i = A("i")
h = B("h")
m = B("m")
c = B("c")

b.v = i
b.y = i
g.r = c
g.s = i
i.v = b
i.y = b
h.r = c
h.s = b
m.r = h
m.s = i
c.r = h
c.s = b
assert h.r.s.v.y.txt == "
class A:
    def __init__(self, txt: str):
        self.v: A = None
        self.y: A = None
        self.txt = txt

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

b = A("b")
g = B("g")
i = A("i")
h = B("h")
m = B("m")
c = B("c")

b.v = i
b.y = i
g.r = c
g.s = i
i.v = b
i.y = b
h.r = c
h.s = b
m.r = h
m.s = i
c.r = h
c.s = b
assert h.r.s.v.y.txt == "b"