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

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

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

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

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

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

a.z = g
b.x = g
b.z = k
c.x = b
c.z = a
j.x = g
j.z = a
k.z = j
g.x = j
g.z = k
h.z = c
assert g.z.z.z.z.x.x.z.txt == "k"