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

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

b = A("b")
n = B("n")
g = B("g")
a = B("a")
i = A("i")
l = B("l")
c = B("c")

b.w = l
n.w = b
n.r = i
g.w = i
g.r = b
a.w = b
a.r = i
i.w = g
l.w = i
l.r = b
c.w = b
c.r = i
assert i.w.r.w.w.w.r.txt == "
class A:
    def __init__(self, txt: str):
        self.w: B = None
        self.txt = txt

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

b = A("b")
n = B("n")
g = B("g")
a = B("a")
i = A("i")
l = B("l")
c = B("c")

b.w = l
n.w = b
n.r = i
g.w = i
g.r = b
a.w = b
a.r = i
i.w = g
l.w = i
l.r = b
c.w = b
c.r = i
assert i.w.r.w.w.w.r.txt == "b"