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

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

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

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

d = A("d")
m = B("m")
g = C("g")
f = D("f")
j = D("j")
b = C("b")
k = B("k")
n = A("n")

d.x = m
d.r = n
m.u = g
m.p = b
m.s = j
g.t = f
f.z = b
j.z = b
b.t = f
k.u = g
k.p = g
k.s = j
n.x = m
n.r = d
assert d.x.u.t.z.t.z.t.txt == "
class A:
    def __init__(self, txt: str):
        self.x: B = None
        self.r: A = None
        self.txt = txt

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

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

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

d = A("d")
m = B("m")
g = C("g")
f = D("f")
j = D("j")
b = C("b")
k = B("k")
n = A("n")

d.x = m
d.r = n
m.u = g
m.p = b
m.s = j
g.t = f
f.z = b
j.z = b
b.t = f
k.u = g
k.p = g
k.s = j
n.x = m
n.r = d
assert d.x.u.t.z.t.z.t.txt == "f"