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

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

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

k.y = c
k.z = d
a.p = f
c.y = g
c.z = f
e.y = c
e.z = d
g.y = j
g.z = a
j.y = g
j.z = a
d.p = a
f.p = a
assert j.z.p.p.txt == "
class A:
    def __init__(self, txt: str):
        self.y: A = None
        self.z: B = None
        self.txt = txt

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

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

k.y = c
k.z = d
a.p = f
c.y = g
c.z = f
e.y = c
e.z = d
g.y = j
g.z = a
j.y = g
j.z = a
d.p = a
f.p = a
assert j.z.p.p.txt == "a"