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

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

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

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

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

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

k.v = c
f.z = k
g.v = j
c.v = g
d.v = k
e.v = k
j.v = e
assert c.v.v.v.v.v.txt == "c"