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

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

j = A("j")
g = B("g")
a = B("a")
d = B("d")
k = A("k")

j.w = d
g.z = a
a.z = g
d.z = g
k.w = d
assert j.w.z.z.z.z.txt == "
class A:
    def __init__(self, txt: str):
        self.w: B = None
        self.txt = txt

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

j = A("j")
g = B("g")
a = B("a")
d = B("d")
k = A("k")

j.w = d
g.z = a
a.z = g
d.z = g
k.w = d
assert j.w.z.z.z.z.txt == "a"