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

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

b = A("b")
g = B("g")
n = B("n")
j = B("j")
h = B("h")
m = A("m")
a = A("a")
c = A("c")

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

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

b = A("b")
g = B("g")
n = B("n")
j = B("j")
h = B("h")
m = A("m")
a = A("a")
c = A("c")

b.s = n
g.r = n
g.y = b
n.r = h
n.y = b
j.r = g
j.y = m
h.r = g
h.y = a
m.s = j
a.s = g
c.s = g
assert g.r.r.r.y.txt == "b"