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

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

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

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

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

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

h.p = f
h.z = d
l.q = f
l.y = h
g.p = b
g.z = d
d.p = b
d.z = k
k.p = l
k.z = j
b.q = f
b.y = g
f.q = b
f.y = h
j.p = f
j.z = k
assert k.p.y.p.y.z.txt == "d"