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

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

d = A("d")
n = B("n")
c = B("c")
i = A("i")
g = B("g")
k = A("k")
j = B("j")

d.z = j
n.y = d
n.v = k
c.y = k
c.v = i
i.z = n
g.y = k
g.v = d
k.z = c
j.y = i
j.v = d
assert n.y.z.v.z.txt == "
class A:
    def __init__(self, txt: str):
        self.z: B = None
        self.txt = txt

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

d = A("d")
n = B("n")
c = B("c")
i = A("i")
g = B("g")
k = A("k")
j = B("j")

d.z = j
n.y = d
n.v = k
c.y = k
c.v = i
i.z = n
g.y = k
g.v = d
k.z = c
j.y = i
j.v = d
assert n.y.z.v.z.txt == "j"