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

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

b = A("b")
g = B("g")
n = A("n")
i = A("i")
j = A("j")

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

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

b = A("b")
g = B("g")
n = A("n")
i = A("i")
j = A("j")

b.y = j
b.w = g
g.r = b
g.s = b
n.y = j
n.w = g
i.y = n
i.w = g
j.y = i
j.w = g
assert i.y.y.y.w.r.txt == "b"