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

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

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

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

k = A("k")
i = B("i")
d = C("d")
g = D("g")
f = C("f")

k.o = i
i.u = f
d.y = f
d.r = i
d.z = k
g.v = f
g.w = d
g.q = i
f.y = d
f.r = i
f.z = k
assert i.u.y.y.y.y.txt == "
class A:
    def __init__(self, txt: str):
        self.o: B = None
        self.txt = txt

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

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

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

k = A("k")
i = B("i")
d = C("d")
g = D("g")
f = C("f")

k.o = i
i.u = f
d.y = f
d.r = i
d.z = k
g.v = f
g.w = d
g.q = i
f.y = d
f.r = i
f.z = k
assert i.u.y.y.y.y.txt == "f"