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

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

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

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

i = A("i")
k = B("k")
e = C("e")
d = D("d")
b = C("b")
j = A("j")
c = C("c")
l = B("l")

i.v = j
k.v = d
k.z = d
e.z = j
d.y = k
b.z = j
j.v = i
c.z = i
l.v = d
l.z = d
assert i.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.v: D = None
        self.z: D = None
        self.txt = txt

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

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

i = A("i")
k = B("k")
e = C("e")
d = D("d")
b = C("b")
j = A("j")
c = C("c")
l = B("l")

i.v = j
k.v = d
k.z = d
e.z = j
d.y = k
b.z = j
j.v = i
c.z = i
l.v = d
l.z = d
assert i.v.v.v.v.v.txt == "j"