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

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

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

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

b = A("b")
n = B("n")
k = C("k")
f = D("f")
m = B("m")
e = A("e")
h = D("h")
i = C("i")
g = D("g")

b.u = n
n.v = k
n.p = g
k.p = b
k.t = b
k.v = i
f.t = i
f.u = g
m.v = k
m.p = h
e.u = n
h.t = i
h.u = f
i.p = e
i.t = e
i.v = k
g.t = k
g.u = h
assert i.v.v.t.u.p.txt == "
class A:
    def __init__(self, txt: str):
        self.u: B = None
        self.txt = txt

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

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

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

b = A("b")
n = B("n")
k = C("k")
f = D("f")
m = B("m")
e = A("e")
h = D("h")
i = C("i")
g = D("g")

b.u = n
n.v = k
n.p = g
k.p = b
k.t = b
k.v = i
f.t = i
f.u = g
m.v = k
m.p = h
e.u = n
h.t = i
h.u = f
i.p = e
i.t = e
i.v = k
g.t = k
g.u = h
assert i.v.v.t.u.p.txt == "g"