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

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

i = A("i")
n = B("n")
f = A("f")
e = A("e")
c = B("c")
b = B("b")
d = A("d")
g = B("g")
k = A("k")

i.z = d
n.v = e
n.w = f
f.z = k
e.z = k
c.v = f
c.w = i
b.v = e
b.w = f
d.z = f
g.v = i
g.w = f
k.z = e
assert k.z.z.z.z.txt == "
class A:
    def __init__(self, txt: str):
        self.z: A = None
        self.txt = txt

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

i = A("i")
n = B("n")
f = A("f")
e = A("e")
c = B("c")
b = B("b")
d = A("d")
g = B("g")
k = A("k")

i.z = d
n.v = e
n.w = f
f.z = k
e.z = k
c.v = f
c.w = i
b.v = e
b.w = f
d.z = f
g.v = i
g.w = f
k.z = e
assert k.z.z.z.z.txt == "k"