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

class B:
    def __init__(self, txt: str):
        self.u: D = None
        self.r: A = None
        self.txt = txt

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

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

m = A("m")
i = B("i")
e = C("e")
f = D("f")
k = C("k")
l = C("l")
d = D("d")
j = A("j")

m.p = f
i.u = d
i.r = m
e.y = k
f.y = i
f.u = d
f.p = d
k.y = l
l.y = k
d.y = i
d.u = f
d.p = f
j.p = f
assert i.u.y.u.y.txt == "
class A:
    def __init__(self, txt: str):
        self.p: D = None
        self.txt = txt

class B:
    def __init__(self, txt: str):
        self.u: D = None
        self.r: A = None
        self.txt = txt

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

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

m = A("m")
i = B("i")
e = C("e")
f = D("f")
k = C("k")
l = C("l")
d = D("d")
j = A("j")

m.p = f
i.u = d
i.r = m
e.y = k
f.y = i
f.u = d
f.p = d
k.y = l
l.y = k
d.y = i
d.u = f
d.p = f
j.p = f
assert i.u.y.u.y.txt == "i"