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

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

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

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

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

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

b.u = g
i.w = n
i.z = g
g.w = n
g.z = i
n.u = g
assert b.u.z.z.txt == "g"