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

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

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

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

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

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

n.z = j
b.s = j
j.s = b
i.z = j
g.s = b
assert b.s.s.s.s.txt == "b"