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

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

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

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

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

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

m.z = f
c.w = a
c.q = a
k.w = j
k.q = j
b.w = a
b.q = g
f.z = m
d.w = c
d.q = b
a.w = c
a.q = d
g.w = a
g.q = c
j.w = d
j.q = a
assert m.z.z.z.z.z.z.z.txt == "f"