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.y: B = None
        self.txt = txt

l = A("l")
h = B("h")
n = A("n")
b = B("b")
d = A("d")
g = A("g")

l.z = h
h.x = g
h.y = b
n.z = b
b.x = l
b.y = h
d.z = h
g.z = b
assert l.z.y.y.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.y: B = None
        self.txt = txt

l = A("l")
h = B("h")
n = A("n")
b = B("b")
d = A("d")
g = A("g")

l.z = h
h.x = g
h.y = b
n.z = b
b.x = l
b.y = h
d.z = h
g.z = b
assert l.z.y.y.txt == "h"