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

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

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

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

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

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

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