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

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

class C:
    def __init__(self, txt: str):
        self.t: B = None
        self.w: B = None
        self.p: B = None
        self.txt = txt

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

i = A("i")
j = B("j")
e = C("e")
m = D("m")
b = A("b")
f = D("f")
g = A("g")

i.u = g
j.z = f
e.t = j
e.w = j
e.p = j
m.y = i
b.u = g
f.y = i
g.u = i
assert g.u.u.u.u.u.txt == "
class A:
    def __init__(self, txt: str):
        self.u: A = None
        self.txt = txt

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

class C:
    def __init__(self, txt: str):
        self.t: B = None
        self.w: B = None
        self.p: B = None
        self.txt = txt

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

i = A("i")
j = B("j")
e = C("e")
m = D("m")
b = A("b")
f = D("f")
g = A("g")

i.u = g
j.z = f
e.t = j
e.w = j
e.p = j
m.y = i
b.u = g
f.y = i
g.u = i
assert g.u.u.u.u.u.txt == "i"