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

d = A("d")
g = B("g")
n = B("n")
i = A("i")
c = A("c")
b = B("b")

d.z = b
g.s = n
n.s = g
i.z = g
c.z = b
b.s = n
assert b.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

d = A("d")
g = B("g")
n = B("n")
i = A("i")
c = A("c")
b = B("b")

d.z = b
g.s = n
n.s = g
i.z = g
c.z = b
b.s = n
assert b.s.s.s.txt == "n"