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

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

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

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

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

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

d.z = a
d.y = f
i.q = g
i.s = b
g.z = c
g.y = i
b.z = c
b.y = c
c.q = g
c.s = g
f.q = b
f.s = d
a.q = g
a.s = b
assert d.y.s.y.s.z.q.txt == "g"