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

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

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

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

j = A("j")
n = B("n")
g = C("g")
m = D("m")
c = D("c")
h = C("h")
b = C("b")
e = D("e")
d = A("d")
f = A("f")

j.u = n
j.v = g
n.v = d
g.x = n
g.v = h
m.p = n
m.r = h
c.p = n
c.r = h
h.x = n
h.v = g
b.x = n
b.v = g
e.p = n
e.r = g
d.u = n
d.v = g
f.u = n
f.v = b
assert f.u.v.u.v.u.txt == "
class A:
    def __init__(self, txt: str):
        self.u: B = None
        self.v: C = None
        self.txt = txt

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

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

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

j = A("j")
n = B("n")
g = C("g")
m = D("m")
c = D("c")
h = C("h")
b = C("b")
e = D("e")
d = A("d")
f = A("f")

j.u = n
j.v = g
n.v = d
g.x = n
g.v = h
m.p = n
m.r = h
c.p = n
c.r = h
h.x = n
h.v = g
b.x = n
b.v = g
e.p = n
e.r = g
d.u = n
d.v = g
f.u = n
f.v = b
assert f.u.v.u.v.u.txt == "n"