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

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

d = A("d")
j = B("j")
b = B("b")
f = B("f")
g = B("g")
c = B("c")
a = B("a")

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

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

d = A("d")
j = B("j")
b = B("b")
f = B("f")
g = B("g")
c = B("c")
a = B("a")

d.z = c
d.w = a
j.w = a
j.y = d
b.w = f
b.y = d
f.w = g
f.y = d
g.w = j
g.y = d
c.w = b
c.y = d
a.w = c
a.y = d
assert g.w.y.z.w.y.z.y.txt == "d"