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

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

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

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

d = A("d")
j = B("j")
i = C("i")
n = D("n")
g = B("g")
f = A("f")
c = A("c")
a = C("a")
m = C("m")
l = D("l")

d.t = j
j.x = d
i.u = g
i.t = l
n.u = i
n.v = c
g.x = d
f.t = g
c.t = g
a.u = j
a.t = l
m.u = g
m.t = n
l.u = a
l.v = f
assert g.x.t.x.txt == "
class A:
    def __init__(self, txt: str):
        self.t: B = None
        self.txt = txt

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

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

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

d = A("d")
j = B("j")
i = C("i")
n = D("n")
g = B("g")
f = A("f")
c = A("c")
a = C("a")
m = C("m")
l = D("l")

d.t = j
j.x = d
i.u = g
i.t = l
n.u = i
n.v = c
g.x = d
f.t = g
c.t = g
a.u = j
a.t = l
m.u = g
m.t = n
l.u = a
l.v = f
assert g.x.t.x.txt == "d"