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

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

c = A("c")
g = B("g")
f = B("f")
m = A("m")
h = B("h")
n = A("n")

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

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

c = A("c")
g = B("g")
f = B("f")
m = A("m")
h = B("h")
n = A("n")

c.r = m
c.y = f
g.w = h
g.v = h
f.w = h
f.v = g
m.r = n
m.y = g
h.w = g
h.v = g
n.r = c
n.y = g
assert g.v.w.w.w.v.w.txt == "g"