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

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

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

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

f = A("f")
c = B("c")
a = C("a")
j = D("j")
g = B("g")
d = B("d")
h = A("h")

f.u = a
c.p = a
c.t = h
c.r = j
c.u = j
a.y = d
j.v = f
g.p = a
g.t = f
g.r = j
g.u = j
d.p = a
d.t = f
d.r = j
d.u = j
h.u = a
assert a.y.t.u.y.txt == "
class A:
    def __init__(self, txt: str):
        self.u: C = None
        self.txt = txt

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

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

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

f = A("f")
c = B("c")
a = C("a")
j = D("j")
g = B("g")
d = B("d")
h = A("h")

f.u = a
c.p = a
c.t = h
c.r = j
c.u = j
a.y = d
j.v = f
g.p = a
g.t = f
g.r = j
g.u = j
d.p = a
d.t = f
d.r = j
d.u = j
h.u = a
assert a.y.t.u.y.txt == "d"