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

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

k = A("k")
g = B("g")
e = A("e")
d = B("d")
j = B("j")
h = B("h")
b = A("b")

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

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

k = A("k")
g = B("g")
e = A("e")
d = B("d")
j = B("j")
h = B("h")
b = A("b")

k.y = d
k.r = d
g.z = b
g.y = b
e.y = d
e.r = g
d.z = b
d.y = b
j.z = k
j.y = k
h.z = k
h.y = e
b.y = j
b.r = h
assert h.y.r.z.r.z.y.z.txt == "b"