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

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

a = A("a")
b = B("b")
e = B("e")
n = B("n")
g = A("g")
j = A("j")
k = B("k")
d = B("d")
f = A("f")

a.x = k
b.r = n
b.z = g
e.r = b
e.z = a
n.r = d
n.z = j
g.x = n
j.x = d
k.r = e
k.z = j
d.r = b
d.z = g
f.x = b
assert k.z.x.r.r.r.r.z.txt == "
class A:
    def __init__(self, txt: str):
        self.x: B = None
        self.txt = txt

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

a = A("a")
b = B("b")
e = B("e")
n = B("n")
g = A("g")
j = A("j")
k = B("k")
d = B("d")
f = A("f")

a.x = k
b.r = n
b.z = g
e.r = b
e.z = a
n.r = d
n.z = j
g.x = n
j.x = d
k.r = e
k.z = j
d.r = b
d.z = g
f.x = b
assert k.z.x.r.r.r.r.z.txt == "g"