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

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

j = A("j")
b = B("b")
f = A("f")
g = B("g")
i = B("i")
h = A("h")
k = B("k")
a = B("a")

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

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

j = A("j")
b = B("b")
f = A("f")
g = B("g")
i = B("i")
h = A("h")
k = B("k")
a = B("a")

j.z = i
b.x = j
b.q = j
f.z = i
g.x = f
g.q = f
i.x = f
i.q = j
h.z = g
k.x = f
k.q = h
a.x = h
a.q = f
assert j.z.x.z.q.z.x.txt == "f"