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

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

b = A("b")
g = B("g")
j = A("j")
d = A("d")
k = B("k")
n = A("n")
c = A("c")
f = A("f")
h = A("h")

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

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

b = A("b")
g = B("g")
j = A("j")
d = A("d")
k = B("k")
n = A("n")
c = A("c")
f = A("f")
h = A("h")

b.z = k
g.q = c
j.z = k
d.z = g
k.q = b
n.z = g
c.z = k
f.z = g
h.z = g
assert j.z.q.z.q.z.q.txt == "b"